httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@hyperreal.org
Subject cvs commit: apache-1.3/src/support htpasswd.c
Date Mon, 08 Mar 1999 20:14:07 GMT
stoddard    99/03/08 12:14:06

  Modified:    src/support htpasswd.c
  Log:
  Fix for argument math in htpasswd.
  Submitted by: Ryan Bloom
  
  Revision  Changes    Path
  1.21      +17 -8     apache-1.3/src/support/htpasswd.c
  
  Index: htpasswd.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/support/htpasswd.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- htpasswd.c	1999/02/03 16:22:34	1.20
  +++ htpasswd.c	1999/03/08 20:14:05	1.21
  @@ -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