You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 1999/08/04 19:52:23 UTC

cvs commit: apache-apr/include apr_file_io.h

rbb         99/08/04 10:52:22

  Modified:    apr/file_io/unix fileio.h open.c readwrite.c
               apr/include apr_config.h.in apr_lib.h apr_win.h
               apr/lib  Makefile.in apr_md5.c apr_snprintf.c
               apr/test Makefile.in
               include  apr_file_io.h
  Added:       apr/lib  apr_getpass.c
               apr/test htdigest.c
  Log:
  All the changes required to get htdigest working with APR on Unix.  Next step,
  NT.  :)
  
  Revision  Changes    Path
  1.9       +1 -0      apache-apr/apr/file_io/unix/fileio.h
  
  Index: fileio.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/fileio.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- fileio.h	1999/07/27 19:26:13	1.8
  +++ fileio.h	1999/08/04 17:51:53	1.9
  @@ -72,6 +72,7 @@
       char * fname;
       int buffered;
       int stated;
  +    int eof_hit;
       mode_t protection;
       uid_t user;
       gid_t group;
  
  
  
  1.33      +25 -1     apache-apr/apr/file_io/unix/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/open.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- open.c	1999/07/28 18:10:57	1.32
  +++ open.c	1999/08/04 17:51:54	1.33
  @@ -92,6 +92,8 @@
    *          APR_EXCL             return error if APR_CREATE and file exists
    * arg 4) Access permissions for file.
    * arg 5) The opened file descriptor.
  + * NOTE:  If mode is -1, the system open command will be called without any
  + *        mode parameters.
    */
   ap_status_t ap_open(ap_context_t *cont, char *fname, ap_int32_t flag,  ap_fileperms_t perm, struct file_t **new)
   {
  @@ -140,13 +142,20 @@
           oflags |= O_TRUNC;
       }
    
  -   (*new)->filedes = open(fname, oflags, mode);
  +    if (mode == -1) {
  +        (*new)->filedes = open(fname, oflags);
  +    }
  +    else {
  +        (*new)->filedes = open(fname, oflags, mode);
  +    }    
       
       if ((*new)->filedes < 0) {
          (*new)->filedes = -1;
  +       (*new)->eof_hit = 1;
           return errno;
       }
       (*new)->stated = 0;  /* we haven't called stat for this file yet. */
  +    (*new)->eof_hit = 0;
       ap_register_cleanup((*new)->cntxt, (void *)(*new), file_cleanup, NULL);
       return APR_SUCCESS;
   }
  @@ -220,4 +229,19 @@
       (*file)->filedes = *thefile;
       return APR_SUCCESS;
   }    
  +
  +/* ***APRDOC********************************************************
  + * ap_status_t ap_eof(ap_file_t *) 
  + *    Are we at the end of the file
  + * arg 1) The apr file we are testing.
  + * NOTE:  Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise.
  + */
  +ap_status_t ap_eof(ap_file_t *fptr)
  +{
  +    char ch;
  +    if (fptr->eof_hit == 1) {
  +        return APR_EOF;
  +    }
  +    APR_SUCCESS;
  +}   
   
  
  
  
  1.14      +74 -1     apache-apr/apr/file_io/unix/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/readwrite.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- readwrite.c	1999/07/28 18:10:58	1.13
  +++ readwrite.c	1999/08/04 17:51:54	1.14
  @@ -73,7 +73,7 @@
    * the available data is read.  The third argument is modified to reflect the
    * number of bytes read. 
    */
  -ap_status_t ap_read(const struct file_t *thefile, void *buf, ap_ssize_t *nbytes)
  +ap_status_t ap_read(struct file_t *thefile, void *buf, ap_ssize_t *nbytes)
   {
       ap_ssize_t rv;
   
  @@ -84,6 +84,9 @@
       
       rv = read(thefile->filedes, buf, *nbytes);
   
  +    if ((*nbytes != rv) && (errno != EINTR)) {
  +        thefile->eof_hit = 1;
  +    }
       *nbytes = rv;
       return APR_SUCCESS;
   }
  @@ -148,4 +151,74 @@
       }
   }
   #endif
  +
  +/* ***APRDOC********************************************************
  + * ap_status_t ap_putc(ap_file_t *, char)
  + *    put a character into the specified file.
  + * arg 1) The file descriptor to write to
  + * arg 2) The character to write.
  + */
  +ap_status_t ap_putc(ap_file_t *thefile, char ch)
  +{
  +    if (write(thefile->filedes, &ch, 1) != 1) {
  +        return errno;
  +    }
  +    return APR_SUCCESS; 
  +}
  +
  +/* ***APRDOC********************************************************
  + * ap_status_t ap_getc(ap_file_t *, char *)
  + *    put a character into the specified file.
  + * arg 1) The file descriptor to write to
  + * arg 2) The character to write.
  + */
  +ap_status_t ap_getc(ap_file_t *thefile, char *ch)
  +{
  +    ssize_t rv = read(thefile->filedes, ch, 1); 
  +    if (rv == 0) {
  +        thefile->eof_hit = TRUE;
  +        return APR_EOF;
  +    }
  +    else if (rv != 1) {
  +        return errno;
  +    }
  +    return APR_SUCCESS; 
  +}
  +
  +static int printf_flush(ap_vformatter_buff_t *vbuff)
  +{
  +    /* I would love to print this stuff out to the file, but I will
  +     * get that working later.  :)  For now, just return.
  +     */
  +    return -1;
  +}
  +
  +API_EXPORT(int) ap_fprintf(struct file_t *fptr, const char *format, ...)
  +{
  +    int cc;
  +    va_list ap;
  +    ap_vformatter_buff_t vbuff;
  +    char *buf;
  +    int len;
  +
  +    buf = malloc(HUGE_STRING_LEN);
  +    if (buf == NULL) {
  +        return 0;
  +    }
  +    /* save one byte for nul terminator */
  +    vbuff.curpos = buf;
  +    vbuff.endpos = buf + len - 1;
  +    va_start(ap, format);
  +#if 0
  +    cc = ap_vformatter(printf_flush, &vbuff, format, ap);
  +    va_end(ap);
  +    *vbuff.curpos = '\0';
  +#endif
  +    vsprintf(buf, format, ap);
  +    len = strlen(buf);
  +    cc = ap_write(fptr, buf, &len);
  +    va_end(ap);
  +    return (cc == -1) ? len : cc;
  +}
  +
   
  
  
  
  1.13      +3 -0      apache-apr/apr/include/apr_config.h.in
  
  Index: apr_config.h.in
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/include/apr_config.h.in,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- apr_config.h.in	1999/07/23 14:41:38	1.12
  +++ apr_config.h.in	1999/08/04 17:51:56	1.13
  @@ -94,6 +94,9 @@
   /* Define if you have the stricmp function.  */
   #undef HAVE_STRICMP
   
  +/* Define if you have the writev function.  */
  +#undef HAVE_WRITEV
  +
   /* Define if you have the <arpa/inet.h> header file.  */
   #undef HAVE_ARPA_INET_H
   
  
  
  
  1.12      +4 -0      apache-apr/apr/include/apr_lib.h
  
  Index: apr_lib.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/include/apr_lib.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- apr_lib.h	1999/07/13 19:51:23	1.11
  +++ apr_lib.h	1999/08/04 17:51:56	1.12
  @@ -65,6 +65,7 @@
   #define APR_LIB_H
   
   #include "apr_general.h"
  +#include "apr_file_io.h"
   #ifndef WIN32
   #include "apr_config.h"
   #else
  @@ -101,6 +102,8 @@
   extern "C" {
   #endif /* __cplusplus */
   
  +#define HUGE_STRING_LEN 8192
  +
   /*
    * Define the structures used by the APR general-purpose library.
    */
  @@ -315,6 +318,7 @@
   API_EXPORT(void) ap_run_cleanup(struct context_t *p, void *data,
   				 ap_status_t (*cleanup) (void *));
   API_EXPORT(void) ap_cleanup_for_exec(void);
  +API_EXPORT(ap_status_t) ap_getpass(const char *prompt, char *pwbuf, size_t *bufsize);
   API_EXPORT_NONSTD(void) ap_null_cleanup(void *data);
   /*
   API_EXPORT(void) ap_note_cleanups_for_fd(ap_pool_t *p, int fd);
  
  
  
  1.8       +0 -2      apache-apr/apr/include/apr_win.h
  
  Index: apr_win.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/include/apr_win.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- apr_win.h	1999/07/02 19:09:16	1.7
  +++ apr_win.h	1999/08/04 17:51:57	1.8
  @@ -105,8 +105,6 @@
   #define __attribute__(__x) 
   #define APR_INLINE 
   
  -#define HUGE_STRING_LEN 8192
  -
   #define API_EXPORT(x)            x
   #define API_EXPORT_NONSTD(x)     x
   #define API_THREAD_FUNC __stdcall
  
  
  
  1.13      +16 -8     apache-apr/apr/lib/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/lib/Makefile.in,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Makefile.in	1999/07/27 18:27:58	1.12
  +++ Makefile.in	1999/08/04 17:52:00	1.13
  @@ -25,7 +25,8 @@
   	apr_signal.o \
   	apr_slack.o \
   	apr_snprintf.o \
  -	apr_tables.o
  +	apr_tables.o \
  +	apr_getpass.o
   
   .c.o:
   	$(CC) $(CFLAGS) -c $(INCLUDES) $<
  @@ -65,22 +66,29 @@
   apr_fnmatch.o: apr_fnmatch.c $(INCDIR)/apr_config.h \
    $(INCDIR)/apr_fnmatch.h $(INCDIR)/apr_lib.h \
    ../../include/apr_general.h ../../include/apr_errno.h \
  + ../../include/apr_file_io.h $(INCDIR)/hsregex.h
  +apr_getpass.o: apr_getpass.c $(INCDIR)/apr_config.h \
  + $(INCDIR)/apr_lib.h ../../include/apr_general.h \
  + ../../include/apr_errno.h ../../include/apr_file_io.h \
    $(INCDIR)/hsregex.h
   apr_md5.o: apr_md5.c $(INCDIR)/apr_config.h $(INCDIR)/apr_md5.h \
    $(INCDIR)/apr_lib.h ../../include/apr_general.h \
  - ../../include/apr_errno.h $(INCDIR)/hsregex.h
  + ../../include/apr_errno.h ../../include/apr_file_io.h \
  + $(INCDIR)/hsregex.h
   apr_pools.o: apr_pools.c $(INCDIR)/apr_config.h \
    ../../include/apr_general.h ../../include/apr_errno.h \
  - $(INCDIR)/apr_pools.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h \
  - ../misc/unix/misc.h ../../include/apr_file_io.h
  + $(INCDIR)/apr_pools.h $(INCDIR)/apr_lib.h \
  + ../../include/apr_file_io.h $(INCDIR)/hsregex.h ../misc/unix/misc.h
   apr_signal.o: apr_signal.c $(INCDIR)/apr_config.h \
    $(INCDIR)/apr_lib.h ../../include/apr_general.h \
  - ../../include/apr_errno.h $(INCDIR)/hsregex.h
  + ../../include/apr_errno.h ../../include/apr_file_io.h \
  + $(INCDIR)/hsregex.h
   apr_slack.o: apr_slack.c $(INCDIR)/apr_config.h
   apr_snprintf.o: apr_snprintf.c $(INCDIR)/apr_config.h \
    $(INCDIR)/apr_lib.h ../../include/apr_general.h \
  - ../../include/apr_errno.h $(INCDIR)/hsregex.h
  + ../../include/apr_errno.h ../../include/apr_file_io.h \
  + $(INCDIR)/hsregex.h
   apr_tables.o: apr_tables.c $(INCDIR)/apr_config.h \
    ../../include/apr_general.h ../../include/apr_errno.h \
  - $(INCDIR)/apr_pools.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h \
  - ../misc/unix/misc.h ../../include/apr_file_io.h
  + $(INCDIR)/apr_pools.h $(INCDIR)/apr_lib.h \
  + ../../include/apr_file_io.h $(INCDIR)/hsregex.h ../misc/unix/misc.h
  
  
  
  1.3       +4 -0      apache-apr/apr/lib/apr_md5.c
  
  Index: apr_md5.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/lib/apr_md5.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_md5.c	1999/06/01 18:15:33	1.2
  +++ apr_md5.c	1999/08/04 17:52:02	1.3
  @@ -104,6 +104,10 @@
   #include "apr_md5.h"
   #include "apr_lib.h"
   
  +#ifdef HAVE_CRYPT_H
  +#include <crypt.h>
  +#endif
  +
   /* Constants for MD5Transform routine.
    */
   
  
  
  
  1.6       +1 -0      apache-apr/apr/lib/apr_snprintf.c
  
  Index: apr_snprintf.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/lib/apr_snprintf.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- apr_snprintf.c	1999/06/02 19:38:01	1.5
  +++ apr_snprintf.c	1999/08/04 17:52:03	1.6
  @@ -1023,3 +1023,4 @@
       *vbuff.curpos = '\0';
       return (cc == -1) ? len : cc;
   }
  +
  
  
  
  1.1                  apache-apr/apr/lib/apr_getpass.c
  
  Index: apr_getpass.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group and was originally based
   * on public domain software written at the National Center for
   * Supercomputing Applications, University of Illinois, Urbana-Champaign.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  /*
   * ap_getpass.c: abstraction to provide for obtaining a password from the
   * command line in whatever way the OS supports.  In the best case, it's a
   * wrapper for the system library's getpass() routine; otherwise, we
   * use one we define ourselves.
   */
  
  #include "apr_config.h"
  #include "apr_errno.h"
  #include <sys/types.h>
  #include <errno.h>
  #include "apr_lib.h"
  
  #ifdef WIN32
  #include <conio.h>
  #endif
  
  #ifndef CHARSET_EBCDIC
  #define LF 10
  #define CR 13
  #else /* CHARSET_EBCDIC */
  #define LF '\n'
  #define CR '\r'
  #endif /* CHARSET_EBCDIC */
  
  #define MAX_STRING_LEN 256
  
  #define ERR_OVERFLOW 5
  
  #ifdef MPE
  /*
   * MPE lacks getpass() and a way to suppress stdin echo.  So for now, just
   * issue the prompt and read the results with echo.  (Ugh).
   */
  
  static char *getpass(const char *prompt)
  {
      static char password[MAX_STRING_LEN];
  
      fputs(prompt, stderr);
      gets((char *) &password);
  
      if (strlen((char *) &password) > (MAX_STRING_LEN - 1)) {
  	password[MAX_STRING_LEN - 1] = '\0';
      }
  
      return (char *) &password;
  }
  
  #endif
  
  #ifdef WIN32
  /*
   * Windows lacks getpass().  So we'll re-implement it here.
   */
  
  static char *getpass(const char *prompt)
  {
      static char password[MAX_STRING_LEN];
      int n = 0;
  
      fputs(prompt, stderr);
      
      while ((password[n] = _getch()) != '\r') {
          if (password[n] >= ' ' && password[n] <= '~') {
              n++;
              printf("*");
          }
  	else {
              printf("\n");
              fputs(prompt, stderr);
              n = 0;
          }
      }
   
      password[n] = '\0';
      printf("\n");
  
      if (n > (MAX_STRING_LEN - 1)) {
          password[MAX_STRING_LEN - 1] = '\0';
      }
  
      return (char *) &password;
  }
  #endif
  
  /*
   * Use the OS getpass() routine (or our own) to obtain a password from
   * the input stream.
   *
   * Exit values:
   *  0: Success
   *  5: Partial success; entered text truncated to the size of the
   *     destination buffer
   *
   * Restrictions: Truncation also occurs according to the host system's
   * getpass() semantics, or at position 255 if our own version is used,
   * but the caller is *not* made aware of it.
   */
  
  API_EXPORT(ap_status_t) ap_getpass(const char *prompt, char *pwbuf, size_t *bufsiz)
  {
      char *pw_got;
      int result = 0;
  
      pw_got = getpass(prompt);
      if (strlen(pw_got) > (*bufsiz - 1)) {
  	*bufsiz = ERR_OVERFLOW;
          return APR_ENAMETOOLONG;
      }
      apr_cpystrn(pwbuf, pw_got, *bufsiz);
      *bufsiz = result;
      return APR_SUCCESS; 
  }
  
  
  
  1.14      +11 -5     apache-apr/apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/Makefile.in,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Makefile.in	1999/07/27 17:58:34	1.13
  +++ Makefile.in	1999/08/04 17:52:14	1.14
  @@ -8,7 +8,7 @@
   CC=@CC@
   RANLIB=@RANLIB@
   CFLAGS=@CFLAGS@ @OPTIM@ 
  -LIBS=-L../network_io -lnetwork -L../threadproc -lthreadproc -L../file_io -lfile -L../misc -lmisc -L../lib -lapr -L../time -ltime -L../locks -llock -L../signal -lsig @LIBS@ 
  +LIBS=-L../network_io -lnetwork -L../threadproc -lthreadproc -L../file_io -lfile -L../misc -lmisc -L../lib -lapr -L../time -ltime -L../locks -llock -L../signal -lsig -lcrypt @LIBS@ 
   LDFLAGS=@LDFLAGS@ $(LIBS)
   INCDIR=../include
   INCDIR1=../../include
  @@ -18,19 +18,22 @@
   	testproc@EXEEXT@ \
   	testsock@EXEEXT@ \
   	testthread@EXEEXT@ \
  -	ab@EXEEXT@ \
   	testtime@EXEEXT@ \
   	testsig@EXEEXT@ \
  -	testargs@EXEEXT@
  +	testargs@EXEEXT@ \
  +	ab@EXEEXT@ \
  +	htdigest@EXEEXT@ 
   
   OBJS= testfile.o \
   	testproc.o \
   	testsock.o \
   	testthread.o \
  -	ab_apr.o \
   	testtime.o \
   	testsig.o \
  -        testargs.o
  +        testargs.o \
  +	ab_apr.o \
  +	htdigest.o
  +
   .c.o:
   	$(CC) -c $(CFLAGS) $(INCLUDES) $<
   
  @@ -44,6 +47,9 @@
   
   ab@EXEEXT@: ab_apr.o
   	$(CC) $(CFLAGS) ab_apr.o -o ab@EXEEXT@ $(LDFLAGS)
  +
  +htdigest@EXEEXT@: htdigest.o
  +	$(CC) $(CFLAGS) htdigest.o -o htdigest@EXEEXT@ $(LDFLAGS)
   
   testproc@EXEEXT@: testproc.o
   	$(CC) $(CFLAGS) testproc.o -o testproc@EXEEXT@ $(LDFLAGS)
  
  
  
  1.1                  apache-apr/apr/test/htdigest.c
  
  Index: htdigest.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group and was originally based
   * on public domain software written at the National Center for
   * Supercomputing Applications, University of Illinois, Urbana-Champaign.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  /******************************************************************************
   ******************************************************************************
   * NOTE! This program is not safe as a setuid executable!  Do not make it
   * setuid!
   ******************************************************************************
   *****************************************************************************/
  /*
   * htdigest.c: simple program for manipulating digest passwd file for Apache
   *
   * by Alexei Kosut, based on htpasswd.c, by Rob McCool
   */
  
  #include "apr_config.h"
  #include "apr_lib.h"
  #include "apr_md5.h"
  #include <sys/types.h>
  #if defined(MPE) || defined(QNX) || defined(WIN32)
  #include <signal.h>
  #else
  #include <sys/signal.h>
  #endif
  
  #ifdef WIN32
  #include <conio.h>
  #define unlink _unlink
  #endif
  
  #ifdef CHARSET_EBCDIC
  #define LF '\n'
  #define CR '\r'
  #else
  #define LF 10
  #define CR 13
  #endif /* CHARSET_EBCDIC */
  
  #define MAX_STRING_LEN 256
  
  char *tn;
  
  static void getword(char *word, char *line, char stop)
  {
      int x = 0, y;
  
      for (x = 0; ((line[x]) && (line[x] != stop)); x++)
  	word[x] = line[x];
  
      word[x] = '\0';
      if (line[x])
  	++x;
      y = 0;
  
      while ((line[y++] = line[x++]));
  }
  
  static int getline(char *s, int n, ap_file_t *f)
  {
      register int i = 0;
      char ch;
  
      while (1) {
  	ap_getc(f, &ch);
              s[i] = ch;
  
  	if (s[i] == CR)
  	    ap_getc(f, &ch);
              s[i] = ch;
  
  	if ((s[i] == 0x4) || (s[i] == LF) || (i == (n - 1))) {
  	    s[i] = '\0';
              if (ap_eof(f) == APR_EOF) {
                  return 1;
              }
              return 0;
  	}
  	++i;
      }
  }
  
  static void putline(ap_file_t *f, char *l)
  {
      int x;
  
      for (x = 0; l[x]; x++)
  	ap_putc(f, l[x]);
      ap_putc(f, '\n');
  }
  
  
  static void add_password(char *user, char *realm, ap_file_t *f)
  {
      char *pw;
      APR_MD5_CTX context;
      unsigned char digest[16];
      char string[MAX_STRING_LEN];
      char pwin[MAX_STRING_LEN];
      char pwv[MAX_STRING_LEN];
      unsigned int i;
      size_t len = sizeof(pwin);
  
      if (ap_getpass("New password: ", pwin, &len) != APR_SUCCESS) {
  	fprintf(stderr, "password too long");
  	exit(5);
      }
      len = sizeof(pwin);
      ap_getpass("Re-type new password: ", pwv, &len);
      if (strcmp(pwin, pwv) != 0) {
  	fprintf(stderr, "They don't match, sorry.\n");
  	if (tn) {
  	    unlink(tn);
  	}
  	exit(1);
      }
      pw = pwin;
      ap_fprintf(f, "%s:%s:", user, realm);
  
      /* Do MD5 stuff */
      sprintf(string, "%s:%s:%s", user, realm, pw);
  
      apr_MD5Init(&context);
      apr_MD5Update(&context, (unsigned char *) string, strlen(string));
      apr_MD5Final(digest, &context);
  
      for (i = 0; i < 16; i++)
  	ap_fprintf(f, "%02x", digest[i]);
  
      ap_fprintf(f, "\n");
  }
  
  static void usage(void)
  {
      fprintf(stderr, "Usage: htdigest [-c] passwordfile realm username\n");
      fprintf(stderr, "The -c flag creates a new file.\n");
      exit(1);
  }
  
  static void interrupted(void)
  {
      fprintf(stderr, "Interrupted.\n");
      if (tn)
  	unlink(tn);
      exit(1);
  }
  
  int main(int argc, char *argv[])
  {
      ap_file_t *tfp, *f;
      char user[MAX_STRING_LEN];
      char realm[MAX_STRING_LEN];
      char line[MAX_STRING_LEN];
      char l[MAX_STRING_LEN];
      char w[MAX_STRING_LEN];
      char x[MAX_STRING_LEN];
      char command[MAX_STRING_LEN];
      int found;
      ap_context_t *context;
      
      ap_create_context(NULL, NULL, &context);
  
      tn = NULL;
      signal(SIGINT, (void (*)(int)) interrupted);
      if (argc == 5) {
  	if (strcmp(argv[1], "-c"))
  	    usage();
  	if (ap_open(context, argv[2], APR_WRITE | APR_CREATE, -1, &tfp) != APR_SUCCESS) {
  	    fprintf(stderr, "Could not open passwd file %s for writing.\n",
  		    argv[2]);
  	    perror("ap_open");
  	    exit(1);
  	}
  	printf("Adding password for %s in realm %s.\n", argv[4], argv[3]);
  	add_password(argv[4], argv[3], tfp);
  	ap_close(tfp);
  	exit(0);
      }
      else if (argc != 4)
  	usage();
  
      tn = tmpnam(NULL);
      if (ap_open(context, tn, APR_WRITE | APR_CREATE, -1, &tfp)!= APR_SUCCESS) {
  	fprintf(stderr, "Could not open temp file.\n");
  	exit(1);
      }
  
      if (ap_open(context, argv[1], APR_READ, -1, &f) != APR_SUCCESS) {
  	fprintf(stderr,
  		"Could not open passwd file %s for reading.\n", argv[1]);
  	fprintf(stderr, "Use -c option to create new one.\n");
  	exit(1);
      }
      strcpy(user, argv[3]);
      strcpy(realm, argv[2]);
  
      found = 0;
      while (!(getline(line, MAX_STRING_LEN, f))) {
  	if (found || (line[0] == '#') || (!line[0])) {
  	    putline(tfp, line);
  	    continue;
  	}
  	strcpy(l, line);
  	getword(w, l, ':');
  	getword(x, l, ':');
  	if (strcmp(user, w) || strcmp(realm, x)) {
  	    putline(tfp, line);
  	    continue;
  	}
  	else {
  	    printf("Changing password for user %s in realm %s\n", user, realm);
  	    add_password(user, realm, tfp);
  	    found = 1;
  	}
      }
      if (!found) {
  	printf("Adding user %s in realm %s\n", user, realm);
  	add_password(user, realm, tfp);
      }
      ap_close(f);
      ap_close(tfp);
  #if defined(OS2) || defined(WIN32)
      sprintf(command, "copy \"%s\" \"%s\"", tn, argv[1]);
  #else
      sprintf(command, "cp %s %s", tn, argv[1]);
  #endif
      system(command);
      unlink(tn);
      return 0;
  }
  
  
  
  1.36      +6 -1      apache-apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/include/apr_file_io.h,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- apr_file_io.h	1999/06/21 18:28:11	1.35
  +++ apr_file_io.h	1999/08/04 17:52:19	1.36
  @@ -108,10 +108,15 @@
   ap_status_t ap_open(ap_context_t *, char *, ap_int32_t, ap_fileperms_t, ap_file_t **);
   ap_status_t ap_close(ap_file_t *);
   ap_status_t ap_remove_file(ap_context_t *, char *);
  +ap_status_t ap_eof(ap_file_t *);
   
  -ap_status_t ap_read(const ap_file_t *, void *, ap_ssize_t *);
  +ap_status_t ap_read(ap_file_t *, void *, ap_ssize_t *);
   ap_status_t ap_write(ap_file_t *, void *, ap_ssize_t *);
   ap_status_t ap_writev(ap_file_t *, const ap_iovec_t *, ap_ssize_t *);
  +ap_status_t ap_putc(ap_file_t *, char);
  +ap_status_t ap_getc(ap_file_t *, char *);
  +API_EXPORT(int) ap_fprintf(ap_file_t *fptr, const char *format, ...)
  +        __attribute__((format(printf,2,3)));
   
   ap_status_t ap_dupfile(ap_file_t *, ap_file_t **);
   ap_status_t ap_getfileinfo(ap_file_t *);