]> arthur.barton.de Git - netatalk.git/blobdiff - bin/afppasswd/afppasswd.c
Cleanup header checks in configure.in
[netatalk.git] / bin / afppasswd / afppasswd.c
index f38ef1099412f586ac64ee3c27e7d16aefd069b3..3125f53ffb7ddd88c04305bc37fd80a3abc3e006 100644 (file)
@@ -1,4 +1,6 @@
 /* 
+ * $Id: afppasswd.c,v 1.19 2005-04-28 20:49:19 bfernhomberg Exp $
+ *
  * Copyright 1999 (c) Adrian Sun (asun@u.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
  *
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 #include <unistd.h>
 #include <ctype.h>
-#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 
 #include <netatalk/endian.h>
 
-#ifdef UAM_RNDNUM
 #include <des.h>
 
 #ifdef USE_CRACKLIB
 #include <crack.h>
-#endif
+#endif /* USE_CRACKLIB */
 
 #define OPT_ISROOT  (1 << 0)
 #define OPT_CREATE  (1 << 1)
@@ -52,7 +54,7 @@
 
 #define FORMAT  ":****************:****************:********\n"
 #define FORMAT_LEN 44
-#define OPTIONS "cafun:p:"
+#define OPTIONS "cafnu:p:"
 #define UID_START 100
 
 #define HEXPASSWDLEN 16
@@ -67,7 +69,7 @@ static void convert_passwd(char *buf, char *newpwd, const int keyfd)
 {
   u_int8_t key[HEXPASSWDLEN];
   Key_schedule schedule;
-  int i, j;
+  unsigned int i, j;
 
   if (!newpwd) {
     /* convert to binary */
@@ -94,7 +96,7 @@ static void convert_passwd(char *buf, char *newpwd, const int keyfd)
       /* decrypt the password */
       ecb_encrypt((C_Block *) buf, (C_Block *) buf, schedule, DES_DECRYPT);
     }
-    memset(schedule, 0, sizeof(schedule));      
+    memset(&schedule, 0, sizeof(schedule));      
   }
 
   if (newpwd) {
@@ -133,7 +135,8 @@ static int update_passwd(const char *path, const char *name, int flags)
   while (fgets(buf, sizeof(buf), fp)) {
     if ((p = strchr(buf, ':'))) {
       /* check for a match */
-      if (strncmp(buf, name, p - buf) == 0) {
+      if (strlen(name) == (p - buf) && 
+          strncmp(buf, name, p - buf) == 0) {
        p++;
        if (!(flags & OPT_ISROOT) && (*p == PASSWD_ILLEGAL)) {
          fprintf(stderr, "Your password is disabled. Please see your administrator.\n");
@@ -174,13 +177,14 @@ found_entry:
   memcpy(password, passwd, sizeof(password));
   password[PASSWDLEN] = '\0';
 #ifdef USE_CRACKLIB
-  if ( (!(flags & OPT_NOCRACK)) and 
-       (passwd = FascistCheck(password, _PATH_CRACKLIB)) ) {
-      fprintf(stderr, "Error: %s\n", passwd);
-      err = -1;
-      goto update_done;
+  if (!(flags & OPT_NOCRACK)) {
+    if (passwd = FascistCheck(password, _PATH_CRACKLIB)) { 
+        fprintf(stderr, "Error: %s\n", passwd);
+        err = -1;
+        goto update_done;
+    } 
   }
-#endif
+#endif /* USE_CRACKLIB */
 
   passwd = getpass("Enter NEW AFP password again: ");
   if (strcmp(passwd, password) == 0) {
@@ -235,7 +239,8 @@ static int create_file(const char *path, uid_t minuid)
     strcat(buf, FORMAT);
     len = strlen(buf);
     if (write(fd, buf, len) != len) {
-      fprintf(stderr, "afppasswd: problem writing to %s: %m\n", path);
+      fprintf(stderr, "afppasswd: problem writing to %s: %s\n", path,
+             strerror(errno));
       err = -1;
       break;
     }
@@ -256,7 +261,7 @@ int main(int argc, char **argv)
   int i, err = 0;
 
   extern char *optarg;
-  extern int optind, opterr;
+  extern int optind;
 
   flags = ((uid = getuid()) == 0) ? OPT_ISROOT : 0;
 
@@ -267,7 +272,7 @@ int main(int argc, char **argv)
     fprintf(stderr, "  -f        force an action\n");
 #ifdef USE_CRACKLIB
     fprintf(stderr, "  -n        disable cracklib checking of passwords\n");
-#endif
+#endif /* USE_CRACKLIB */
     fprintf(stderr, "  -u uid    minimum uid to use, defaults to 100\n");
     fprintf(stderr, "  -p path   path to afppasswd file\n");
     return -1;
@@ -280,6 +285,7 @@ int main(int argc, char **argv)
       break;
     case 'a': /* add a new user */
       flags |= OPT_ADDUSER;
+      break;
     case 'f': /* force an action */
       flags |= OPT_FORCE;
       break;
@@ -290,7 +296,7 @@ int main(int argc, char **argv)
     case 'n': /* disable CRACKLIB check */
       flags |= OPT_NOCRACK;
       break;
-#endif
+#endif /* USE_CRACKLIB */
     case 'p': /* path to afppasswd file */
       path = optarg;
       break;
@@ -299,14 +305,22 @@ int main(int argc, char **argv)
       break;
     }
   }
-
+  
   if (err || (optind + ((flags & OPT_CREATE) ? 0 : 
                        (flags & OPT_ISROOT)) != argc)) {
 #ifdef USE_CRACKLIB
     fprintf(stderr, "Usage: afppasswd [-acfn] [-u minuid] [-p path] [username]\n");
-#else
+#else /* USE_CRACKLIB */
     fprintf(stderr, "Usage: afppasswd [-acf] [-u minuid] [-p path] [username]\n");
-#endif
+#endif /* USE_CRACKLIB */
+    fprintf(stderr, "  -a        add a new user\n");
+    fprintf(stderr, "  -c        create and initialize password file or specific user\n");
+    fprintf(stderr, "  -f        force an action\n");
+#ifdef USE_CRACKLIB
+    fprintf(stderr, "  -n        disable cracklib checking of passwords\n");
+#endif /* USE_CRACKLIB */
+    fprintf(stderr, "  -u uid    minimum uid to use, defaults to 100\n");
+    fprintf(stderr, "  -p path   path to afppasswd file\n");
     return -1;
   }
 
@@ -340,13 +354,3 @@ int main(int argc, char **argv)
     return -1;
   }
 }
-#else
-
-main(int argc, char **argv)
-{
-  fprintf(stderr, "afppasswd is only useful if you're using centralized passwords\n");
-  fprintf(stderr, "for the Random Number authentication methods.\n");
-  return -1;
-}
-#endif
-