]>
git.saurik.com Git - apple/system_cmds.git/blob - chkpasswd.tproj/passwd.c
21155737326e7b4348f8b54462b2e4e36c0cfa66
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@
24 #define INFO_NETINFO 0
27 #define INFO_DIRECTORYSERVICES 3
30 #define _PASSWD_FILE "/etc/master.passwd"
32 #define _PASSWD_FILE "/etc/passwd"
42 #include <netinfo/ni.h>
43 #include "stringops.h"
46 #define _PASSWORD_LEN 8
49 static int literal
= 0;
51 extern int file_check_passwd(char *, char *);
52 extern int netinfo_check_passwd(char *, char *);
53 extern int nis_check_passwd(char *, char *);
54 extern int ds_check_passwd(char *, char *);
57 checkpasswd(char *name
, char *old_pw
)
62 printf("Checking password for %s.\n", name
);
66 if (old_pw
== NULL
) isNull
= 1;
67 if ((isNull
== 0) && (old_pw
[0] == '\0')) isNull
= 1;
70 p
= getpass("Password:");
71 sleep(1); // make sure this doesn't go too quickly
72 if (strcmp(literal
? p
: crypt(p
, old_pw
), old_pw
))
75 fprintf(stderr
, "Sorry\n");
85 fprintf(stderr
, "usage: chkpasswd [-i infosystem] [-l location] [-c] [name]\n");
86 fprintf(stderr
, "supported infosystems are:\n");
87 fprintf(stderr
, " netinfo\n");
88 fprintf(stderr
, " file\n");
89 fprintf(stderr
, " nis\n");
90 fprintf(stderr
, " opendirectory\n");
91 fprintf(stderr
, "for netinfo, location may be a domain name or server/tag\n");
92 fprintf(stderr
, "for file, location may be a file name (%s is the default)\n",
94 fprintf(stderr
, "for nis, location may be a NIS domainname\n");
95 fprintf(stderr
, "for opendirectory, location may be a directory node name\n");
96 fprintf(stderr
, "if -c is specified, the password you supply is compared\n");
97 fprintf(stderr
, "verbatim without first being crypted\n");
102 main(int argc
, char *argv
[])
108 infosystem
= INFO_DIRECTORYSERVICES
;
112 for (i
= 1; i
< argc
; i
++)
114 if (!strcmp(argv
[i
], "-i"))
118 fprintf(stderr
, "no argument for -i option\n");
122 if (!strcmp(argv
[i
], "NetInfo")) infosystem
= INFO_NETINFO
;
123 else if (!strcmp(argv
[i
], "netinfo")) infosystem
= INFO_NETINFO
;
124 else if (!strcmp(argv
[i
], "File")) infosystem
= INFO_FILE
;
125 else if (!strcmp(argv
[i
], "file")) infosystem
= INFO_FILE
;
126 else if (!strcmp(argv
[i
], "NIS")) infosystem
= INFO_NIS
;
127 else if (!strcmp(argv
[i
], "nis")) infosystem
= INFO_NIS
;
128 else if (!strcmp(argv
[i
], "YP")) infosystem
= INFO_NIS
;
129 else if (!strcmp(argv
[i
], "yp")) infosystem
= INFO_NIS
;
130 else if (!strcasecmp(argv
[i
], "opendirectory")) infosystem
= INFO_DIRECTORYSERVICES
;
133 fprintf(stderr
, "unknown info system \"%s\"\n", argv
[i
]);
138 else if (!strcmp(argv
[i
], "-l"))
142 fprintf(stderr
, "no argument for -l option\n");
148 else if (!strcmp(argv
[i
], "-c")) literal
++;
149 else if (user
== NULL
) user
= argv
[i
];
155 if ((pw
= getpwuid(getuid())) == NULL
|| (user
= pw
->pw_name
) == NULL
)
157 fprintf(stderr
, "you don't have a login name\n");
165 netinfo_check_passwd(user
, locn
);
168 file_check_passwd(user
, locn
);
171 nis_check_passwd(user
, locn
);
173 case INFO_DIRECTORYSERVICES
:
174 ds_check_passwd(user
, locn
);