httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@hyperreal.org
Subject cvs commit: apache-apr/pthreads/src/support htpasswd.c
Date Mon, 08 Mar 1999 15:58:36 GMT
rbb         99/03/08 07:58:36

  Modified:    pthreads/src/support htpasswd.c
  Log:
  Fix for argument math in htpasswd.  If given:
      htpasswd -c passwdfile
  It wouldn't complain.  If given
      htpasswd passwdfile user test
  It would try to open the file user to store passwords in.
  
  Both bugs fixed, and the argument logic parses arguments much better now.
  
  Revision  Changes    Path
  1.3       +17 -8     apache-apr/pthreads/src/support/htpasswd.c
  
  Index: htpasswd.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/support/htpasswd.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- htpasswd.c	1999/02/07 06:30:19	1.2
  +++ htpasswd.c	1999/03/08 15:58:35	1.3
  @@ -214,6 +214,8 @@
       int found;
       int use_md5 = 0;
       int newfile = 0;
  +    int currarg = 1;
  +    int filearg;
   
       tn = NULL;
       signal(SIGINT, (void (*)(int)) interrupted);
  @@ -225,9 +227,6 @@
       if (argc < 3) {
   	    usage();
       }
  -    else {
  -        strcpy(filename, argv[argc - 2]);
  -    }
   
       /* I would rather use getopt, but Windows and UNIX seem to handle getopt
        * differently, so I am doing the argument checking by hand.
  @@ -235,14 +234,24 @@
       
       if (!strcmp(argv[1],"-c") || !strcmp(argv[2],"-c")) {
           newfile = 1;
  +        currarg++;
       }
       if (!strcmp(argv[1],"-m") || !strcmp(argv[2],"-m")) {
           use_md5 = 1;
  +        currarg++;
       }
   
       if (!strcmp(argv[1], "-cm") || !strcmp(argv[2], "-mc")) {
           use_md5 = 1;
           newfile = 1;
  +        currarg++;
  +    }
  +
  +    strcpy(filename, argv[currarg]);
  +    filearg = currarg++;
  +
  +    if (argc <= filearg + 1) {
  +        usage();
       }
   
   #ifdef WIN32
  @@ -258,8 +267,8 @@
   	    perror("fopen");
   	    exit(1);
   	}
  -	printf("Adding password for %s.\n", argv[argc-1]);
  -	add_password(argv[argc - 1], tfp, use_md5);
  +	printf("Adding password for %s.\n", argv[currarg]);
  +	add_password(argv[currarg], tfp, use_md5);
   	fclose(tfp);
   	return(0);
       }
  @@ -270,15 +279,15 @@
   	exit(1);
       }
   
  -    if (!(f = fopen(argv[argc - 2], "r+"))) {
  +    if (!(f = fopen(argv[filearg], "r+"))) {
           fprintf(stderr, "Could not open password file %s for reading.\n",
  -                argv[argc - 2]);
  +                argv[filearg]);
           fprintf(stderr, "Use -c option to create a new one\n");
   	fclose(tfp);
   	unlink(tn);
   	exit(1);
       }
  -    strcpy(user, argv[argc - 1]);
  +    strcpy(user, argv[currarg]);
   
       found = 0;
       while (!(getline(line, MAX_STRING_LEN, f))) {
  
  
  

Mime
View raw message