~lastrosade/jsthttpd

a5568c270f4d9f141595fec5b14d9353100b7ff2 — Anthony G. Basile 7 years ago a1843e5
Fix white spaces

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
4 files changed, 106 insertions(+), 106 deletions(-)

M extras/htpasswd.c
M src/fdwatch.c
M src/libhttpd.c
M src/thttpd.c
M extras/htpasswd.c => extras/htpasswd.c +72 -72
@@ 43,7 43,7 @@ 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] = line[x];

    word[x] = '\0';
    if(line[x]) ++x;


@@ 56,16 56,16 @@ static int get_line(char *s, int n, FILE *f) {
    register int i=0;

    while(1) {
        s[i] = (char)fgetc(f);
	s[i] = (char)fgetc(f);

        if(s[i] == CR)
            s[i] = fgetc(f);
	if(s[i] == CR)
	    s[i] = fgetc(f);

        if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) {
            s[i] = '\0';
            return (feof(f) ? 1 : 0);
        }
        ++i;
	if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) {
	    s[i] = '\0';
	    return (feof(f) ? 1 : 0);
	}
	++i;
    }
}



@@ 79,12 79,12 @@ static void putline(FILE *f,char *l) {

/* From local_passwd.c (C) Regents of Univ. of California blah blah */
static unsigned char itoa64[] =         /* 0 ... 63 => ascii - 64 */
        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

static void to64(register char *s, register long v, register int n) {
    while (--n >= 0) {
        *s++ = itoa64[v&0x3f];
        v >>= 6;
	*s++ = itoa64[v&0x3f];
	v >>= 6;
    }
}



@@ 137,9 137,9 @@ add_password( char* user, FILE* f )
    to64( &salt[0], random(), 2 );
    cpw = crypt( pw, salt );
    if (cpw)
        (void) fprintf( f, "%s:%s\n", user, cpw );
	(void) fprintf( f, "%s:%s\n", user, cpw );
    else
        (void) fprintf( stderr, "crypt() returned NULL, sorry\n" );
	(void) fprintf( stderr, "crypt() returned NULL, sorry\n" );
    }

static void usage(void) {


@@ 167,93 167,93 @@ int main(int argc, char *argv[]) {
    tfd = -1;
    signal(SIGINT,(void (*)(int))interrupted);
    if(argc == 4) {
        if(strcmp(argv[1],"-c"))
            usage();
        if(!(tfp = fopen(argv[2],"w"))) {
            fprintf(stderr,"Could not open passwd file %s for writing.\n",
                    argv[2]);
            perror("fopen");
            exit(1);
        }
        if (strlen(argv[2]) > (sizeof(pwfilename) - 1)) {
            fprintf(stderr, "%s: filename is too long\n", argv[0]);
	if(strcmp(argv[1],"-c"))
	    usage();
	if(!(tfp = fopen(argv[2],"w"))) {
	    fprintf(stderr,"Could not open passwd file %s for writing.\n",
		    argv[2]);
	    perror("fopen");
	    exit(1);
	}
	if (strlen(argv[2]) > (sizeof(pwfilename) - 1)) {
	    fprintf(stderr, "%s: filename is too long\n", argv[0]);
	    exit(1);
        }
        if (((strchr(argv[2], ';')) != NULL) || ((strchr(argv[2], '>')) != NULL)) {
	}
	if (((strchr(argv[2], ';')) != NULL) || ((strchr(argv[2], '>')) != NULL)) {
	    fprintf(stderr, "%s: filename contains an illegal character\n",
		argv[0]);
	    exit(1);
        }
        if (strlen(argv[3]) > (sizeof(user) - 1)) {
	}
	if (strlen(argv[3]) > (sizeof(user) - 1)) {
	    fprintf(stderr, "%s: username is too long\n", argv[0],
		sizeof(user) - 1);
	    exit(1);
        }
        if ((strchr(argv[3], ':')) != NULL) {
            fprintf(stderr, "%s: username contains an illegal character\n",
                argv[0]);
            exit(1);
        }
        printf("Adding password for %s.\n",argv[3]);
        add_password(argv[3],tfp);
        fclose(tfp);
        exit(0);
	}
	if ((strchr(argv[3], ':')) != NULL) {
	    fprintf(stderr, "%s: username contains an illegal character\n",
		argv[0]);
	    exit(1);
	}
	printf("Adding password for %s.\n",argv[3]);
	add_password(argv[3],tfp);
	fclose(tfp);
	exit(0);
    } else if(argc != 3) usage();

    tfd = mkstemp(temp_template);
    if(!(tfp = fdopen(tfd,"w"))) {
        fprintf(stderr,"Could not open temp file.\n");
        exit(1);
	fprintf(stderr,"Could not open temp file.\n");
	exit(1);
    }

    if (strlen(argv[1]) > (sizeof(pwfilename) - 1)) {
        fprintf(stderr, "%s: filename is too long\n", argv[0]);
        exit(1);
	fprintf(stderr, "%s: filename is too long\n", argv[0]);
	exit(1);
    }
    if (((strchr(argv[1], ';')) != NULL) || ((strchr(argv[1], '>')) != NULL)) {
        fprintf(stderr, "%s: filename contains an illegal character\n",
                argv[0]);
        exit(1);
	fprintf(stderr, "%s: filename contains an illegal character\n",
		argv[0]);
	exit(1);
    }
    if (strlen(argv[2]) > (sizeof(user) - 1)) {
        fprintf(stderr, "%s: username is too long\n", argv[0],
                sizeof(user) - 1);
        exit(1);
	fprintf(stderr, "%s: username is too long\n", argv[0],
		sizeof(user) - 1);
	exit(1);
    }
    if ((strchr(argv[2], ':')) != NULL) {
        fprintf(stderr, "%s: username contains an illegal character\n",
                argv[0]);
        exit(1);
	fprintf(stderr, "%s: username contains an illegal character\n",
		argv[0]);
	exit(1);
    }
    if(!(f = fopen(argv[1],"r"))) {
        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);
	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[2]);

    found = 0;
    while(!(get_line(line,MAX_STRING_LEN,f))) {
        if(found || (line[0] == '#') || (!line[0])) {
            putline(tfp,line);
            continue;
        }
        strcpy(l,line);
        getword(w,l,':');
        if(strcmp(user,w)) {
            putline(tfp,line);
            continue;
        }
        else {
            printf("Changing password for user %s\n",user);
            add_password(user,tfp);
            found = 1;
        }
	if(found || (line[0] == '#') || (!line[0])) {
	    putline(tfp,line);
	    continue;
	}
	strcpy(l,line);
	getword(w,l,':');
	if(strcmp(user,w)) {
	    putline(tfp,line);
	    continue;
	}
	else {
	    printf("Changing password for user %s\n",user);
	    add_password(user,tfp);
	    found = 1;
	}
    }
    if(!found) {
        printf("Adding user %s\n",user);
        add_password(user,tfp);
	printf("Adding user %s\n",user);
	add_password(user,tfp);
    }
    fclose(f);
    fclose(tfp);

M src/fdwatch.c => src/fdwatch.c +2 -2
@@ 780,8 780,8 @@ select_watch( long timeout_msecs )
    mfd = select_get_maxfd();
    if ( timeout_msecs == INFTIM )
       r = select(
           mfd + 1, &working_rfdset, &working_wfdset, (fd_set*) 0,
           (struct timeval*) 0 );
	   mfd + 1, &working_rfdset, &working_wfdset, (fd_set*) 0,
	   (struct timeval*) 0 );
    else
	{
	struct timeval timeout;

M src/libhttpd.c => src/libhttpd.c +29 -29
@@ 1064,9 1064,9 @@ auth_check2( httpd_conn* hc, char* dirname  )
	 strcmp( authinfo, prevuser ) == 0 )
	{
	/* Yes.  Check against the cached encrypted password. */
        crypt_result = crypt( authpass, prevcryp );
        if ( ! crypt_result )
            return -1;
	crypt_result = crypt( authpass, prevcryp );
	if ( ! crypt_result )
	    return -1;
	if ( strcmp( crypt_result, prevcryp ) == 0 )
	    {
	    /* Ok! */


@@ 1116,9 1116,9 @@ auth_check2( httpd_conn* hc, char* dirname  )
	    /* Yes. */
	    (void) fclose( fp );
	    /* So is the password right? */
            crypt_result = crypt( authpass, cryp );
            if ( ! crypt_result )
                return -1;
	    crypt_result = crypt( authpass, cryp );
	    if ( ! crypt_result )
		return -1;
	    if ( strcmp( crypt_result, cryp ) == 0 )
		{
		/* Ok! */


@@ 2213,7 2213,7 @@ httpd_parse_request( httpd_conn* hc )
		cp = &buf[16];
		cp += strspn( cp, " \t" );
		inet_aton( cp, &(hc->client_addr.sa_in.sin_addr) );
	        }
		}
#ifdef LOG_UNKNOWN_HEADERS
	    else if ( strncasecmp( buf, "Accept-Charset:", 15 ) == 0 ||
		      strncasecmp( buf, "Accept-Language:", 16 ) == 0 ||


@@ 2581,28 2581,28 @@ figure_mime( httpd_conn* hc )
		break;
		}
	    }
        /* Binary search for a matching type extension. */
        top = n_typ_tab - 1;
        bot = 0;
        while ( top >= bot )
            {
            mid = ( top + bot ) / 2;
            r = strncasecmp( ext, typ_tab[mid].ext, ext_len );
            if ( r < 0 )
                top = mid - 1;
            else if ( r > 0 )
                bot = mid + 1;
            else
                if ( ext_len < typ_tab[mid].ext_len )
                    top = mid - 1;
                else if ( ext_len > typ_tab[mid].ext_len )
                    bot = mid + 1;
                else
                    {
                    hc->type = typ_tab[mid].val;
                    goto done;
                    }
            }
	/* Binary search for a matching type extension. */
	top = n_typ_tab - 1;
	bot = 0;
	while ( top >= bot )
	    {
	    mid = ( top + bot ) / 2;
	    r = strncasecmp( ext, typ_tab[mid].ext, ext_len );
	    if ( r < 0 )
		top = mid - 1;
	    else if ( r > 0 )
		bot = mid + 1;
	    else
		if ( ext_len < typ_tab[mid].ext_len )
		    top = mid - 1;
		else if ( ext_len > typ_tab[mid].ext_len )
		    bot = mid + 1;
		else
		    {
		    hc->type = typ_tab[mid].val;
		    goto done;
		    }
	    }
	}

    done:

M src/thttpd.c => src/thttpd.c +3 -3
@@ 516,7 516,7 @@ main( int argc, char** argv )
	    exit( 0 );
	    }
#ifdef HAVE_SETSID
        (void) setsid();
	(void) setsid();
#endif /* HAVE_SETSID */
#endif /* HAVE_DAEMON */
	}


@@ 526,7 526,7 @@ main( int argc, char** argv )
	** process.
	*/
#ifdef HAVE_SETSID
        (void) setsid();
	(void) setsid();
#endif /* HAVE_SETSID */
	}



@@ 699,7 699,7 @@ main( int argc, char** argv )
	    syslog( LOG_WARNING, "initgroups - %m" );
#ifdef HAVE_SETLOGIN
	/* Set login name. */
        (void) setlogin( user );
	(void) setlogin( user );
#endif /* HAVE_SETLOGIN */
	/* Set uid. */
	if ( setuid( uid ) < 0 )