Changeset 5893

Show
Ignore:
Timestamp:
03/21/10 03:15:36 (3 years ago)
Author:
jow
Message:

uhttpd: finish basic auth support, read realms from /etc/httpd.conf

Location:
luci/trunk/contrib/package/uhttpd/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/contrib/package/uhttpd/src/uhttpd-utils.c

    r5892 r5893  
    483483static int uh_realm_count = 0; 
    484484 
    485 struct auth_realm * uh_auth_add( 
    486     char *path, char *realm, char *user, char *pass 
    487 ) { 
     485struct auth_realm * uh_auth_add(char *path, char *user, char *pass) 
     486{ 
    488487    struct auth_realm *new = NULL; 
    489488    struct passwd *pwd; 
     
    496495 
    497496        memset(new, 0, sizeof(struct auth_realm)); 
    498  
    499         memcpy(new->realm, realm, 
    500             min(strlen(realm), sizeof(new->realm) - 1)); 
    501497 
    502498        memcpy(new->path, path, 
     
    634630            "Content-Length: 23\r\n\r\n" 
    635631            "Authorization Required\n", 
    636                 req->version, realm ? realm->realm : "" 
     632                req->version, cl->server->conf->realm 
    637633        ); 
    638634 
  • luci/trunk/contrib/package/uhttpd/src/uhttpd-utils.h

    r5892 r5893  
    8080 
    8181 
    82 struct auth_realm * uh_auth_add( 
    83     char *path, char *realm, char *user, char *pass 
    84 ); 
     82struct auth_realm * uh_auth_add(char *path, char *user, char *pass); 
    8583 
    8684int uh_auth_check( 
  • luci/trunk/contrib/package/uhttpd/src/uhttpd.c

    r5892 r5893  
    1717 */ 
    1818 
     19#define _XOPEN_SOURCE 500   /* crypt() */ 
     20 
    1921#include "uhttpd.h" 
    2022#include "uhttpd-utils.h" 
     
    3941{ 
    4042    run = 0; 
     43} 
     44 
     45static void uh_config_parse(const char *path) 
     46{ 
     47    FILE *c; 
     48    char line[512]; 
     49    char *user = NULL; 
     50    char *pass = NULL; 
     51    char *eol  = NULL; 
     52 
     53    if( (c = fopen(path ? path : "/etc/httpd.conf", "r")) != NULL ) 
     54    { 
     55        memset(line, 0, sizeof(line)); 
     56 
     57        while( fgets(line, sizeof(line) - 1, c) ) 
     58        { 
     59            if( (line[0] == '/') && (strchr(line, ':') != NULL) ) 
     60            { 
     61                if( !(user = strchr(line, ':')) || (*user++ = 0) || 
     62                    !(pass = strchr(user, ':')) || (*pass++ = 0) || 
     63                    !(eol = strchr(pass, '\n')) || (*eol++  = 0) ) 
     64                        continue; 
     65 
     66                if( !uh_auth_add(line, user, pass) ) 
     67                { 
     68                    fprintf(stderr, 
     69                        "Can not manage more than %i basic auth realms, " 
     70                        "will skip the rest\n", UH_LIMIT_AUTHREALMS 
     71                    ); 
     72 
     73                    break; 
     74                }  
     75            } 
     76        } 
     77 
     78        fclose(c); 
     79    } 
    4180} 
    4281 
     
    399438#endif 
    400439 
    401     while( (opt = getopt(argc, argv, "fC:K:p:s:h:c:l:L:d:")) > 0 ) 
     440    while( (opt = getopt(argc, argv, "fC:K:p:s:h:c:l:L:d:r:m:x:")) > 0 ) 
    402441    { 
    403442        switch(opt) 
     
    468507#ifdef HAVE_CGI 
    469508            /* cgi prefix */ 
    470             case 'c': 
     509            case 'x': 
    471510                conf.cgi_prefix = optarg; 
    472511                break; 
     
    502541                break; 
    503542 
     543            /* basic auth realm */ 
     544            case 'r': 
     545                conf.realm = optarg; 
     546                break; 
     547 
     548            /* md5 crypt */ 
     549            case 'm': 
     550                printf("%s\n", crypt(optarg, "$1$")); 
     551                exit(0); 
     552                break; 
     553 
     554            /* config file */ 
     555            case 'c': 
     556                conf.file = optarg; 
     557                break; 
     558 
    504559            default: 
    505560                fprintf(stderr, 
    506561                    "Usage: %s -p [addr:]port [-h docroot]\n" 
    507                     "   -p  Bind to specified address and port, multiple allowed\n" 
     562                    "   -f              Do not fork to background\n" 
     563                    "   -c file         Configuration file, default is '/etc/httpd.conf'\n" 
     564                    "   -p [addr:]port  Bind to specified address and port, multiple allowed\n" 
    508565#ifdef HAVE_TLS 
    509                     "   -s  Like -p but provide HTTPS on this port\n" 
    510                     "   -C  ASN.1 server certificate file\n" 
    511                     "   -K  ASN.1 server private key file\n" 
    512 #endif 
    513                     "   -h  Specify the document root, default is '.'\n" 
    514                     "   -f  Do not fork to background\n" 
     566                    "   -s [addr:]port  Like -p but provide HTTPS on this port\n" 
     567                    "   -C file         ASN.1 server certificate file\n" 
     568                    "   -K file         ASN.1 server private key file\n" 
     569#endif 
     570                    "   -h directory    Specify the document root, default is '.'\n" 
    515571#ifdef HAVE_LUA 
    516                     "   -l  URL prefix for Lua handler, default is '/lua'\n" 
    517                     "   -L  Lua handler script, omit to disable Lua\n" 
     572                    "   -l string       URL prefix for Lua handler, default is '/lua'\n" 
     573                    "   -L file         Lua handler script, omit to disable Lua\n" 
    518574#endif 
    519575#ifdef HAVE_CGI 
    520                     "   -c  URL prefix for CGI handler, default is '/cgi-bin'\n" 
    521 #endif 
    522                     "   -d  URL decode given string\n" 
     576                    "   -x string       URL prefix for CGI handler, default is '/cgi-bin'\n" 
     577#endif 
     578                    "   -d string       URL decode given string\n" 
     579                    "   -r string       Specify basic auth realm\n" 
     580                    "   -m string       MD5 crypt given string\n" 
    523581                    "\n", argv[0] 
    524582                ); 
     
    549607        exit(1); 
    550608    } 
     609 
     610    /* default realm */ 
     611    if( ! conf.realm ) 
     612        conf.realm = "Protected Area"; 
     613 
     614    /* config file */ 
     615    uh_config_parse(conf.file); 
    551616 
    552617#ifdef HAVE_CGI 
  • luci/trunk/contrib/package/uhttpd/src/uhttpd.h

    r5892 r5893  
    5252struct config { 
    5353    char docroot[PATH_MAX]; 
     54    char *realm; 
     55    char *file; 
    5456#ifdef HAVE_CGI 
    5557    char *cgi_prefix; 
     
    8991struct auth_realm { 
    9092    char path[PATH_MAX]; 
    91     char realm[128]; 
    9293    char user[32]; 
    9394    char pass[128];