/*
- * 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
* 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,
* 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 <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
+#include <string.h>
#include "stringops.h"
#define TEMP_FILE "/tmp/.pwtmp"
#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;
return s;
}
-struct passwd *
+static struct passwd *
parse_user(char *line)
{
static struct passwd pw = {0};
return &pw;
}
-struct passwd *
+static struct passwd *
find_user(char *uname, FILE *fp)
{
char *line;
rewind(fp);
- while (NULL != (line = getline(fp)))
+ while (NULL != (line = _getline(fp)))
{
if (line[0] == '#') continue;
pw = parse_user(line);
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+");
rewind(fp);
- while (NULL != (line = getline(fp)))
+ while (NULL != (line = _getline(fp)))
{
if (line[0] == '#')
{
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);
exit(1);
}
- while (NULL != (line = getline(tfp)))
+ while (NULL != (line = _getline(tfp)))
{
fprintf(fp, "%s", line);
if (line[0] != '#') fprintf(fp, "\n");
fclose(tfp);
unlink(fname);
}
+#endif /* 0 */
int
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("");