islocal: fix coding style

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-11-13 19:32:10 +01:00 committed by Sami Kerola
parent 0a065b7ae6
commit 43b53f57c1
1 changed files with 39 additions and 40 deletions

View File

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