]> git.saurik.com Git - apple/system_cmds.git/blobdiff - passwd.tproj/passwd.c
system_cmds-550.6.tar.gz
[apple/system_cmds.git] / passwd.tproj / passwd.c
index 0eb30fad1e42baf8c34046f9e6ca4cba7cb920f2..67ee59f23e207ded097daf64e3bc4dc216bc359e 100644 (file)
  */
 #include <TargetConditionals.h>
 
-#define INFO_FILE 1
-#define INFO_NIS 2
-#if !TARGET_OS_EMBEDDED
-#define INFO_OPEN_DIRECTORY 3
-#endif
-
-#ifndef __SLICK__
 #define _PASSWD_FILE "/etc/master.passwd"
-#else
-#define _PASSWD_FILE "/etc/passwd"
-#endif
 
 #include <stdio.h>
 #include <errno.h>
@@ -40,7 +30,7 @@
 #include <libc.h>
 #include <ctype.h>
 #include <string.h>
-#include "stringops.h"
+#include "passwd.h"
 
 #ifdef __SLICK__
 #define _PASSWORD_LEN 8
@@ -50,17 +40,12 @@ char* progname = "passwd";
 
 static char *saltchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
 
-extern int file_passwd(char *, char *);
-extern int nis_passwd(char *, char *);
-#ifdef INFO_OPEN_DIRECTORY
-extern int od_passwd(char *, char *, char*);
-#endif
-
 void
 getpasswd(char *name, int isroot, int minlen, int mixcase, int nonalpha,
        char *old_pw, char **new_pw, char **old_clear, char **new_clear)
 {
-       int i, tries, len, pw_ok, upper, lower, alpha, notalpha;
+       int i, tries, pw_ok, upper, lower, alpha, notalpha;
+    size_t len;
        int isNull;
        char *p;
        static char obuf[_PASSWORD_LEN+1];
@@ -160,18 +145,20 @@ getpasswd(char *name, int isroot, int minlen, int mixcase, int nonalpha,
        return;
 }
 
-void
-usage()
+static void
+usage(void)
 {
-       fprintf(stderr, "usage: %s [-i infosystem] [-l location] [-u authname] [name]\n", progname);
+       fprintf(stderr, "usage: %s [-i infosystem] -l location]] [-u authname] [name]\n", progname);
        fprintf(stderr, "  infosystem:\n");
        fprintf(stderr, "    file\n");
        fprintf(stderr, "    NIS\n");
        fprintf(stderr, "    OpenDirectory\n");
+       fprintf(stderr, "    PAM\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, "    PAM            location is not used\n");
        exit(1);
 }
 
@@ -184,25 +171,40 @@ main(int argc, char *argv[])
        int infosystem, ch;
        int free_user = 0;
        
+#ifdef INFO_PAM
+       infosystem = INFO_PAM;
+#else
 #ifdef INFO_OPEN_DIRECTORY
-       /* since OpenDirectory works for most infosystems, make it the default */
        infosystem = INFO_OPEN_DIRECTORY;
 #else
        infosystem = INFO_FILE;
 #endif
-       
+#endif
+
+#ifdef INFO_OPEN_DIRECTORY
+       /* PAM is the default infosystem, but we still want to use OpenDirectory directly when run by root */
+       if (0 == getuid())
+               infosystem = INFO_OPEN_DIRECTORY;
+#endif
+
        while ((ch = getopt(argc, argv, "i:l:u:")) != -1)
                switch(ch) {
                case 'i':
                        if (!strcasecmp(optarg, "file")) {
                                infosystem = INFO_FILE;
+#ifdef INFO_NIS
                        } else if (!strcasecmp(optarg, "NIS")) {
                                infosystem = INFO_NIS;
                        } else if (!strcasecmp(optarg, "YP")) {
                                infosystem = INFO_NIS;
+#endif
 #ifdef INFO_OPEN_DIRECTORY
                        } else if (!strcasecmp(optarg, "opendirectory")) {
                                infosystem = INFO_OPEN_DIRECTORY;
+#endif
+#ifdef INFO_PAM
+                       } else if (!strcasecmp(optarg, "PAM")) {
+                               infosystem = INFO_PAM;
 #endif
                        } else {
                                fprintf(stderr, "%s: Unknown info system \'%s\'.\n",
@@ -230,6 +232,11 @@ main(int argc, char *argv[])
                user = argv[0];
        }
 
+#ifdef INFO_PAM
+       if (INFO_PAM == infosystem && NULL != locn)
+               usage();
+#endif
+
        if (user == NULL)
        {
                /*
@@ -259,13 +266,20 @@ main(int argc, char *argv[])
                case INFO_FILE:
                        file_passwd(user, locn);
                        break;
+#ifdef INFO_NIS
                case INFO_NIS:
                        nis_passwd(user, locn);
                        break;
+#endif
 #ifdef INFO_OPEN_DIRECTORY
                case INFO_OPEN_DIRECTORY:
                        od_passwd(user, locn, auth);
                        break;
+#endif
+#ifdef INFO_PAM
+               case INFO_PAM:
+                       pam_passwd(user);
+                       break;
 #endif
        }