From 5fd83771641d15c418f747bd343ba6738d3875f7 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 9 May 2021 14:20:58 -0400 Subject: Import macOS userland adv_cmds-176 basic_cmds-55 bootstrap_cmds-116.100.1 developer_cmds-66 diskdev_cmds-667.40.1 doc_cmds-53.60.1 file_cmds-321.40.3 mail_cmds-35 misc_cmds-34 network_cmds-606.40.1 patch_cmds-17 remote_cmds-63 shell_cmds-216.60.1 system_cmds-880.60.2 text_cmds-106 --- system_cmds/chkpasswd.tproj/passwd.c | 174 +++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 system_cmds/chkpasswd.tproj/passwd.c (limited to 'system_cmds/chkpasswd.tproj/passwd.c') diff --git a/system_cmds/chkpasswd.tproj/passwd.c b/system_cmds/chkpasswd.tproj/passwd.c new file mode 100644 index 0000000..bff8280 --- /dev/null +++ b/system_cmds/chkpasswd.tproj/passwd.c @@ -0,0 +1,174 @@ +/* + * 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 + * Source License Version 1.0 (the 'License'). You may not use this file + * 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, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * 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@ + */ +#define INFO_FILE 1 +#define INFO_NIS 2 +#define INFO_OPEN_DIRECTORY 3 +#define INFO_PAM 4 + +#ifndef __SLICK__ +#define _PASSWD_FILE "/etc/master.passwd" +#else +#define _PASSWD_FILE "/etc/passwd" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include "stringops.h" + +#ifdef __SLICK__ +#define _PASSWORD_LEN 8 +#endif + +#include "passwd.h" + +const char* progname = "chkpasswd"; + +static int literal = 0; + +void +checkpasswd(char *name, char *old_pw) +{ + int isNull; + char *p; + + printf("Checking password for %s.\n", name); + + p = ""; + isNull = 0; + if (old_pw == NULL) isNull = 1; + if ((isNull == 0) && (old_pw[0] == '\0')) isNull = 1; + if (isNull == 0) + { + p = getpass("Password:"); + sleep(1); // make sure this doesn't go too quickly + if (strcmp(literal ? p : crypt(p, old_pw), old_pw)) + { + errno = EACCES; + fprintf(stderr, "Sorry\n"); + exit(1); + } + } + return; +} + +static void +usage(void) +{ + fprintf(stderr, "usage: chkpasswd [-i infosystem] [-l location] [-c] [name]\n"); + fprintf(stderr, " infosystem:\n"); + fprintf(stderr, " file\n"); + fprintf(stderr, " NIS\n"); + fprintf(stderr, " OpenDirectory\n"); + fprintf(stderr, " location (for infosystem):\n"); + fprintf(stderr, " file location is path to file (default is %s)\n", _PASSWD_FILE); + fprintf(stderr, " NIS location is NIS domain name\n"); + fprintf(stderr, " OpenDirectory location is directory node name\n"); + fprintf(stderr, " -c: supplied password is compared verbatim without first\n"); + fprintf(stderr, " being crypted\n"); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + char* user = NULL; + char* locn = NULL; + int infosystem, ch; + + infosystem = INFO_PAM; + + while ((ch = getopt(argc, argv, "ci:l:")) != -1) { + switch(ch) { + case 'i': + if (!strcasecmp(optarg, "file")) { + infosystem = INFO_FILE; + } else if (!strcasecmp(optarg, "NIS")) { + infosystem = INFO_NIS; + } else if (!strcasecmp(optarg, "YP")) { + infosystem = INFO_NIS; + } else if (!strcasecmp(optarg, "opendirectory")) { + infosystem = INFO_OPEN_DIRECTORY; + } else if (!strcasecmp(optarg, "PAM")) { + infosystem = INFO_PAM; + } else { + fprintf(stderr, "%s: Unknown info system \'%s\'.\n", + progname, optarg); + usage(); + } + break; + case 'l': + locn = optarg; + break; + case 'c': + literal++; + break; + case '?': + default: + usage(); + break; + } + } + argc -= optind; + argv += optind; + + if (argc > 1) { + usage(); + } else if (argc == 1) { + user = argv[0]; + } + + if (user == NULL) { + struct passwd* pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_name != NULL) { + user = strdup(pw->pw_name); + } + if (user == NULL) { + fprintf(stderr, "you don't have a login name\n"); + exit(1); + } + } + + switch (infosystem) + { + case INFO_FILE: + file_check_passwd(user, locn); + break; + case INFO_NIS: + nis_check_passwd(user, locn); + break; + case INFO_OPEN_DIRECTORY: + od_check_passwd(user, locn); + break; + case INFO_PAM: + pam_check_passwd(user); + break; + } + + exit(0); +} -- cgit v1.2.3-56-ge451