]>
git.saurik.com Git - apple/system_cmds.git/blob - system_cmds-597.1.1/chkpasswd.tproj/passwd.c
408fe0326c882633a4eac90f92e7543f5e311baa
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 #define INFO_OPEN_DIRECTORY 3
30 #define _PASSWD_FILE "/etc/master.passwd"
32 #define _PASSWD_FILE "/etc/passwd"
42 #include "stringops.h"
45 #define _PASSWORD_LEN 8
48 const char* progname
= "chkpasswd";
50 static int literal
= 0;
52 extern int file_check_passwd(char *, char *);
53 extern int nis_check_passwd(char *, char *);
54 extern int od_check_passwd(char *, char *);
55 extern int pam_check_passwd(char *);
58 checkpasswd(char *name
, char *old_pw
)
63 printf("Checking password for %s.\n", name
);
67 if (old_pw
== NULL
) isNull
= 1;
68 if ((isNull
== 0) && (old_pw
[0] == '\0')) isNull
= 1;
71 p
= getpass("Password:");
72 sleep(1); // make sure this doesn't go too quickly
73 if (strcmp(literal
? p
: crypt(p
, old_pw
), old_pw
))
76 fprintf(stderr
, "Sorry\n");
86 fprintf(stderr
, "usage: chkpasswd [-i infosystem] [-l location] [-c] [name]\n");
87 fprintf(stderr
, " infosystem:\n");
88 fprintf(stderr
, " file\n");
89 fprintf(stderr
, " NIS\n");
90 fprintf(stderr
, " OpenDirectory\n");
91 fprintf(stderr
, " location (for infosystem):\n");
92 fprintf(stderr
, " file location is path to file (default is %s)\n", _PASSWD_FILE
);
93 fprintf(stderr
, " NIS location is NIS domain name\n");
94 fprintf(stderr
, " OpenDirectory location is directory node name\n");
95 fprintf(stderr
, " -c: supplied password is compared verbatim without first\n");
96 fprintf(stderr
, " being crypted\n");
101 main(int argc
, char *argv
[])
107 infosystem
= INFO_PAM
;
109 while ((ch
= getopt(argc
, argv
, "ci:l:")) != -1) {
112 if (!strcasecmp(optarg
, "file")) {
113 infosystem
= INFO_FILE
;
114 } else if (!strcasecmp(optarg
, "NIS")) {
115 infosystem
= INFO_NIS
;
116 } else if (!strcasecmp(optarg
, "YP")) {
117 infosystem
= INFO_NIS
;
118 } else if (!strcasecmp(optarg
, "opendirectory")) {
119 infosystem
= INFO_OPEN_DIRECTORY
;
120 } else if (!strcasecmp(optarg
, "PAM")) {
121 infosystem
= INFO_PAM
;
123 fprintf(stderr
, "%s: Unknown info system \'%s\'.\n",
145 } else if (argc
== 1) {
150 struct passwd
* pw
= getpwuid(getuid());
151 if (pw
!= NULL
&& pw
->pw_name
!= NULL
) {
152 user
= strdup(pw
->pw_name
);
155 fprintf(stderr
, "you don't have a login name\n");
163 file_check_passwd(user
, locn
);
166 nis_check_passwd(user
, locn
);
168 case INFO_OPEN_DIRECTORY
:
169 od_check_passwd(user
, locn
);
172 pam_check_passwd(user
);