X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/20e66415abeb3fec26bdbd0c220fb926593ab135..c0bbac3af796bf66522d3c580f1596aef9d86002:/chkpasswd.tproj/file_passwd.c diff --git a/chkpasswd.tproj/file_passwd.c b/chkpasswd.tproj/file_passwd.c index 51fc8c1..90f54f2 100644 --- a/chkpasswd.tproj/file_passwd.c +++ b/chkpasswd.tproj/file_passwd.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2016 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public @@ -10,7 +10,7 @@ * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -18,7 +18,7 @@ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." - * + * * @APPLE_LICENSE_HEADER_END@ */ #include @@ -26,6 +26,7 @@ #include #include #include +#include #include "stringops.h" #define TEMP_FILE "/tmp/.pwtmp" @@ -35,20 +36,18 @@ #define _PASSWD_FIELDS 10 #define BUFSIZE 8192 -extern void checkpasswd(char *, char *); +#include "passwd.h" -static int do_compat = 1; - -char * -getline(FILE *fp) +static char * +_getline(FILE *fp) { static char s[BUFSIZE]; - int len; + size_t len; - s[0] = '\0'; + s[0] = '\0'; - fgets(s, BUFSIZE, fp); - if (s == NULL || s[0] == '\0') return NULL; + fgets(s, BUFSIZE, fp); + if (s[0] == '\0') return NULL; if (s[0] == '#') return s; @@ -58,7 +57,7 @@ getline(FILE *fp) return s; } -struct passwd * +static struct passwd * parse_user(char *line) { static struct passwd pw = {0}; @@ -108,7 +107,7 @@ parse_user(char *line) return &pw; } -struct passwd * +static struct passwd * find_user(char *uname, FILE *fp) { char *line; @@ -116,7 +115,7 @@ find_user(char *uname, FILE *fp) rewind(fp); - while (NULL != (line = getline(fp))) + while (NULL != (line = _getline(fp))) { if (line[0] == '#') continue; pw = parse_user(line); @@ -128,14 +127,15 @@ find_user(char *uname, FILE *fp) return (struct passwd *)NULL; } -void +#if 0 +static void rewrite_file(char *pwname, FILE *fp, struct passwd *newpw) { char *line; struct passwd *pw; FILE *tfp, *cfp; char fname[256]; - + sprintf(fname, "%s.%d", TEMP_FILE, getpid()); tfp = fopen(fname, "w+"); @@ -173,7 +173,7 @@ rewrite_file(char *pwname, FILE *fp, struct passwd *newpw) rewind(fp); - while (NULL != (line = getline(fp))) + while (NULL != (line = _getline(fp))) { if (line[0] == '#') { @@ -197,7 +197,7 @@ rewrite_file(char *pwname, FILE *fp, struct passwd *newpw) continue; } - fprintf(tfp, "%s:%s:%d:%d:%s:%d:%d:%s:%s:%s\n", + fprintf(tfp, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n", newpw->pw_name, newpw->pw_passwd, newpw->pw_uid, newpw->pw_gid, newpw->pw_class, newpw->pw_change, newpw->pw_expire, newpw->pw_gecos, newpw->pw_dir, newpw->pw_shell); @@ -233,7 +233,7 @@ rewrite_file(char *pwname, FILE *fp, struct passwd *newpw) exit(1); } - while (NULL != (line = getline(tfp))) + while (NULL != (line = _getline(tfp))) { fprintf(fp, "%s", line); if (line[0] != '#') fprintf(fp, "\n"); @@ -242,6 +242,7 @@ rewrite_file(char *pwname, FILE *fp, struct passwd *newpw) fclose(tfp); unlink(fname); } +#endif /* 0 */ int file_check_passwd(char *uname, char *locn) @@ -253,8 +254,7 @@ file_check_passwd(char *uname, char *locn) fname = _PASSWD_FILE; if (locn != NULL) fname = locn; - fp = fopen(fname, "r"); - if (fp == NULL) + if (access(fname,R_OK) || (fp = fopen(fname, "r")) == NULL) { fprintf(stderr, "can't read file \"%s\": ", fname); perror("");