]>
git.cameronkatri.com Git - apple_cmds.git/blob - system_cmds/chkpasswd.tproj/passwd.c
2 * Copyright (c) 1999-2016 Apple 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
50 const char* progname
= "chkpasswd";
52 static int literal
= 0;
55 checkpasswd(char *name
, char *old_pw
)
60 printf("Checking password for %s.\n", name
);
64 if (old_pw
== NULL
) isNull
= 1;
65 if ((isNull
== 0) && (old_pw
[0] == '\0')) isNull
= 1;
68 p
= getpass("Password:");
69 sleep(1); // make sure this doesn't go too quickly
70 if (strcmp(literal
? p
: crypt(p
, old_pw
), old_pw
))
73 fprintf(stderr
, "Sorry\n");
83 fprintf(stderr
, "usage: chkpasswd [-i infosystem] [-l location] [-c] [name]\n");
84 fprintf(stderr
, " infosystem:\n");
85 fprintf(stderr
, " file\n");
86 fprintf(stderr
, " NIS\n");
87 fprintf(stderr
, " OpenDirectory\n");
88 fprintf(stderr
, " location (for infosystem):\n");
89 fprintf(stderr
, " file location is path to file (default is %s)\n", _PASSWD_FILE
);
90 fprintf(stderr
, " NIS location is NIS domain name\n");
91 fprintf(stderr
, " OpenDirectory location is directory node name\n");
92 fprintf(stderr
, " -c: supplied password is compared verbatim without first\n");
93 fprintf(stderr
, " being crypted\n");
98 main(int argc
, char *argv
[])
104 infosystem
= INFO_PAM
;
106 while ((ch
= getopt(argc
, argv
, "ci:l:")) != -1) {
109 if (!strcasecmp(optarg
, "file")) {
110 infosystem
= INFO_FILE
;
111 } else if (!strcasecmp(optarg
, "NIS")) {
112 infosystem
= INFO_NIS
;
113 } else if (!strcasecmp(optarg
, "YP")) {
114 infosystem
= INFO_NIS
;
115 } else if (!strcasecmp(optarg
, "opendirectory")) {
116 infosystem
= INFO_OPEN_DIRECTORY
;
117 } else if (!strcasecmp(optarg
, "PAM")) {
118 infosystem
= INFO_PAM
;
120 fprintf(stderr
, "%s: Unknown info system \'%s\'.\n",
142 } else if (argc
== 1) {
147 struct passwd
* pw
= getpwuid(getuid());
148 if (pw
!= NULL
&& pw
->pw_name
!= NULL
) {
149 user
= strdup(pw
->pw_name
);
152 fprintf(stderr
, "you don't have a login name\n");
160 file_check_passwd(user
, locn
);
163 nis_check_passwd(user
, locn
);
165 case INFO_OPEN_DIRECTORY
:
166 od_check_passwd(user
, locn
);
169 pam_check_passwd(user
);