]>
git.saurik.com Git - apple/system_cmds.git/blob - chkpasswd.tproj/passwd.c
ac50cd0dfa7e574e0ddda2cacd08b855d883f8be
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_DIRECTORYSERVICES 3
29 #define _PASSWD_FILE "/etc/master.passwd"
31 #define _PASSWD_FILE "/etc/passwd"
41 #include "stringops.h"
44 #define _PASSWORD_LEN 8
47 static int literal
= 0;
49 extern int file_check_passwd(char *, char *);
50 extern int nis_check_passwd(char *, char *);
51 extern int ds_check_passwd(char *, char *);
54 checkpasswd(char *name
, char *old_pw
)
59 printf("Checking password for %s.\n", name
);
63 if (old_pw
== NULL
) isNull
= 1;
64 if ((isNull
== 0) && (old_pw
[0] == '\0')) isNull
= 1;
67 p
= getpass("Password:");
68 sleep(1); // make sure this doesn't go too quickly
69 if (strcmp(literal
? p
: crypt(p
, old_pw
), old_pw
))
72 fprintf(stderr
, "Sorry\n");
82 fprintf(stderr
, "usage: chkpasswd [-i infosystem] [-l location] [-c] [name]\n");
83 fprintf(stderr
, "supported infosystems are:\n");
84 fprintf(stderr
, " file\n");
85 fprintf(stderr
, " nis\n");
86 fprintf(stderr
, " opendirectory\n");
87 fprintf(stderr
, "for file, location may be a file name (%s is the default)\n",
89 fprintf(stderr
, "for nis, location may be a NIS domainname\n");
90 fprintf(stderr
, "for opendirectory, location may be a directory node name\n");
91 fprintf(stderr
, "if -c is specified, the password you supply is compared\n");
92 fprintf(stderr
, "verbatim without first being crypted\n");
97 main(int argc
, char *argv
[])
103 infosystem
= INFO_DIRECTORYSERVICES
;
107 for (i
= 1; i
< argc
; i
++)
109 if (!strcmp(argv
[i
], "-i"))
113 fprintf(stderr
, "no argument for -i option\n");
117 if (!strcmp(argv
[i
], "File")) infosystem
= INFO_FILE
;
118 else if (!strcmp(argv
[i
], "file")) infosystem
= INFO_FILE
;
119 else if (!strcmp(argv
[i
], "NIS")) infosystem
= INFO_NIS
;
120 else if (!strcmp(argv
[i
], "nis")) infosystem
= INFO_NIS
;
121 else if (!strcmp(argv
[i
], "YP")) infosystem
= INFO_NIS
;
122 else if (!strcmp(argv
[i
], "yp")) infosystem
= INFO_NIS
;
123 else if (!strcasecmp(argv
[i
], "opendirectory")) infosystem
= INFO_DIRECTORYSERVICES
;
126 fprintf(stderr
, "unknown info system \"%s\"\n", argv
[i
]);
131 else if (!strcmp(argv
[i
], "-l"))
135 fprintf(stderr
, "no argument for -l option\n");
141 else if (!strcmp(argv
[i
], "-c")) literal
++;
142 else if (user
== NULL
) user
= argv
[i
];
148 if ((pw
= getpwuid(getuid())) == NULL
|| (user
= pw
->pw_name
) == NULL
)
150 fprintf(stderr
, "you don't have a login name\n");
158 file_check_passwd(user
, locn
);
161 nis_check_passwd(user
, locn
);
163 case INFO_DIRECTORYSERVICES
:
164 ds_check_passwd(user
, locn
);