islocal: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
0a065b7ae6
commit
43b53f57c1
|
@ -1,42 +1,40 @@
|
|||
/*
|
||||
islocal.c - returns true if user is registered in the local
|
||||
/etc/passwd file. Written by Alvaro Martinez Echevarria,
|
||||
alvaro@enano.etsit.upm.es, to allow peaceful coexistence with yp. Nov 94.
|
||||
|
||||
Hacked a bit by poe@daimi.aau.dk
|
||||
See also ftp://ftp.daimi.aau.dk/pub/linux/poe/admutil*
|
||||
|
||||
Hacked by Peter Breitenlohner, peb@mppmu.mpg.de,
|
||||
to distinguish user names where one is a prefix of the other,
|
||||
and to use "pathnames.h". Oct 5, 96.
|
||||
|
||||
1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
|
||||
- added Native Language Support
|
||||
|
||||
2008-04-06 James Youngman, jay@gnu.org
|
||||
- Completely rewritten to remove assumption that /etc/passwd
|
||||
lines are < 1024 characters long. Also added unit tests.
|
||||
|
||||
*/
|
||||
/*
|
||||
* islocal.c - returns true if user is registered in the local
|
||||
* /etc/passwd file. Written by Alvaro Martinez Echevarria,
|
||||
* alvaro@enano.etsit.upm.es, to allow peaceful coexistence with yp. Nov 94.
|
||||
*
|
||||
* Hacked a bit by poe@daimi.aau.dk
|
||||
* See also ftp://ftp.daimi.aau.dk/pub/linux/poe/admutil*
|
||||
*
|
||||
* Hacked by Peter Breitenlohner, peb@mppmu.mpg.de,
|
||||
* to distinguish user names where one is a prefix of the other,
|
||||
* and to use "pathnames.h". Oct 5, 96.
|
||||
*
|
||||
* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
|
||||
* - added Native Language Support
|
||||
*
|
||||
* 2008-04-06 James Youngman, jay@gnu.org
|
||||
* - Completely rewritten to remove assumption that /etc/passwd
|
||||
* lines are < 1024 characters long. Also added unit tests.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "islocal.h"
|
||||
#include "nls.h"
|
||||
#include "pathnames.h"
|
||||
#include "islocal.h"
|
||||
|
||||
static int
|
||||
is_local_in_file(const char *user, const char *filename)
|
||||
static int is_local_in_file(const char *user, const char *filename)
|
||||
{
|
||||
int local = 0;
|
||||
size_t match;
|
||||
int chin, skip;
|
||||
FILE *f;
|
||||
|
||||
if (NULL == (f=fopen(filename, "r")))
|
||||
return -1;
|
||||
if (NULL == (f = fopen(filename, "r")))
|
||||
return -1;
|
||||
|
||||
match = 0u;
|
||||
skip = 0;
|
||||
|
@ -51,20 +49,22 @@ is_local_in_file(const char *user, const char *filename)
|
|||
} else {
|
||||
if (':' == chin) {
|
||||
if (0 == user[match]) {
|
||||
local = 1; /* Success. */
|
||||
/* next line has no test coverage, but it is
|
||||
* just an optimisation anyway. */
|
||||
/* Success. */
|
||||
local = 1;
|
||||
/* next line has no test coverage,
|
||||
* but it is just an optimisation
|
||||
* anyway. */
|
||||
break;
|
||||
} else {
|
||||
/* we read a whole username, but it is
|
||||
* the wrong user. Skip to the next
|
||||
* line. */
|
||||
/* we read a whole username, but it
|
||||
* is the wrong user. Skip to the
|
||||
* next line. */
|
||||
skip = 1;
|
||||
}
|
||||
} else if ('\n' == chin) {
|
||||
/* This line contains no colon; it's malformed.
|
||||
* No skip since we are already at the start of
|
||||
* the next line. */
|
||||
/* This line contains no colon; it's
|
||||
* malformed. No skip since we are already
|
||||
* at the start of the next line. */
|
||||
match = 0u;
|
||||
} else if (chin != user[match]) {
|
||||
/* username does not match. */
|
||||
|
@ -78,8 +78,7 @@ is_local_in_file(const char *user, const char *filename)
|
|||
return local;
|
||||
}
|
||||
|
||||
int
|
||||
is_local(const char *user)
|
||||
int is_local(const char *user)
|
||||
{
|
||||
int rv;
|
||||
if ((rv = is_local_in_file(user, _PATH_PASSWD)) < 0) {
|
||||
|
@ -93,11 +92,11 @@ is_local(const char *user)
|
|||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 2) {
|
||||
fprintf(stderr, "usage: %s <passwdfile> <username> [...]\n", argv[0]);
|
||||
fprintf(stderr, "usage: %s <passwdfile> <username> [...]\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
} else {
|
||||
int i;
|
||||
|
|
Loading…
Reference in New Issue