config.c

Go to the documentation of this file.
00001 /* config.c by Michael Temari 02/26/96
00002  *
00003  * This file is part of httpd.
00004  *
00005  * 02/26/1996                   Michael Temari <Michael@TemWare.Com>
00006  * 07/07/1996 Initial Release   Michael Temari <Michael@TemWare.Com>
00007  * 12/29/2002                   Michael Temari <Michael@TemWare.Com>
00008  *
00009  */
00010 #include <sys/types.h>
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string.h>
00014 #include <ctype.h>
00015 #include <pwd.h>
00016 
00017 #include "utility.h"
00018 #include "config.h"
00019 
00020 struct mtype *mtype = NULL;
00021 struct msufx *msufx = NULL;
00022 struct vhost *vhost = NULL;
00023 struct vpath *vpath = NULL;
00024 struct dirsend *dirsend = NULL;
00025 struct auth *auth = NULL;
00026 struct auth *proxyauth = NULL;
00027 char *direxec = NULL;
00028 char *srvrroot = "";
00029 char *LogFile = NULL;
00030 char *DbgFile = NULL;
00031 char *User = NULL;
00032 char *Chroot = NULL;
00033 
00034 _PROTOTYPE(static int doconfig, (char *cfg_file));
00035 _PROTOTYPE(static int doinclude, (char *parms[], int np));
00036 _PROTOTYPE(static int domtype, (char *parms[], int np));
00037 _PROTOTYPE(static struct auth *findauth, (char *name));
00038 _PROTOTYPE(static int dovhost, (char *parms[], int np));
00039 _PROTOTYPE(static int dovpath, (char *parms[], int np));
00040 _PROTOTYPE(static int dosrvrroot, (char *parms[], int np));
00041 _PROTOTYPE(static int dodirsend, (char *parms[], int np));
00042 _PROTOTYPE(static int dodirexec, (char *parms[], int np));
00043 _PROTOTYPE(static char *subvpath, (char *s));
00044 _PROTOTYPE(static int dologfile, (char *parms[], int np));
00045 _PROTOTYPE(static int dodbgfile, (char *parms[], int np));
00046 _PROTOTYPE(static int douser, (char *parms[], int np));
00047 _PROTOTYPE(static int dochroot, (char *parms[], int np));
00048 _PROTOTYPE(static int adduser, (struct auth *pauth, char *user));
00049 _PROTOTYPE(static int doauth, (char *parms[], int np));
00050 _PROTOTYPE(static int doproxyauth, (char *parms[], int np));
00051 
00052 int readconfig(cfg_file, testing)
00053 char *cfg_file;
00054 int testing;
00055 {
00056 int s;
00057 char *cfg;
00058 struct msufx *ps;
00059 struct mtype *pt;
00060 struct vhost *ph;
00061 struct vpath *pv;
00062 struct dirsend *pd;
00063 struct auth *pa;
00064 
00065    cfg = HTTPD_CONFIG_FILE;
00066    if(cfg_file != (char *)NULL)
00067         if(*cfg_file)
00068                 cfg = cfg_file;
00069 
00070    s = doconfig(cfg);
00071 
00072    if(testing) {
00073         printf("ServerRoot: %s\n", srvrroot);
00074         printf("UserName: %s\n", User == NULL ? "" : User);
00075         printf("Chroot: %s\n", Chroot == NULL ? "" : Chroot);
00076         printf("LogFile: %s\n", LogFile == NULL ? "" : LogFile);
00077         printf("DbgFile: %s\n", DbgFile == NULL ? "" : DbgFile);
00078         printf("DirSend:");
00079         for(pd = dirsend; pd != NULL; pd = pd->next)
00080                 printf(" %s", pd->file);
00081         printf("\n");
00082         printf("DirExec: %s\n", direxec == NULL ? "" : direxec);
00083         for(ph = vhost; ph != NULL; ph = ph->next)
00084                 printf("VHost: %s %s\n", ph->hname, ph->root);
00085         for(pa = auth; pa != NULL; pa = pa->next)
00086                 printf("Auth: %s %s %d %s\n",
00087                         pa->name, pa->desc, pa->urlaccess, pa->passwdfile);
00088         for(pa = proxyauth; pa != NULL; pa = pa->next)
00089                 printf("ProxyAuth: %s %s %d %s\n",
00090                         pa->name, pa->desc, pa->urlaccess, pa->passwdfile);
00091         for(pv = vpath; pv != NULL; pv = pv->next)
00092                 printf("Vpath: %s %s %s %d\n",
00093                         pv->from, pv->to, pv->auth->name, pv->urlaccess);
00094         for(pt = mtype; pt != NULL; pt = pt->next) {
00095                 printf("MType: %s :", pt->mimetype);
00096                 for(ps = pt->msufx; ps != NULL; ps = ps->tnext)
00097                         printf(" '%s'", ps->suffix);
00098                 printf("\n");
00099         }
00100         for(ps = msufx; ps != NULL; ps = ps->snext)
00101                 printf("Suffix: %s\t%s\n", ps->suffix, ps->mtype->mimetype);
00102    }
00103 
00104    return(s);
00105 }
00106 
00107 static int doconfig(cfg_file)
00108 char *cfg_file;
00109 {
00110 FILE *fp;
00111 int np;
00112 int s;
00113 char *p;
00114 char ltype[40];
00115 char *parms[30];
00116 static char buffer[2048];
00117 
00118    if((fp = fopen(cfg_file, "r")) == (FILE *)NULL) {
00119         fprintf(stderr, "httpd: Could not read %s config file.\n", cfg_file);
00120         return(-1);
00121    }
00122 
00123    *ltype = '\0';
00124 
00125    while(fgets(buffer, sizeof(buffer), fp) != (char *)NULL) {
00126         if(buffer[0] == '#') continue;  /* skip comments */
00127         np = getparms(buffer, parms, sizeof(parms)/sizeof(parms[0]));
00128         if(np == 0) continue;   /* blank line */
00129         if(parms[0] == (char *)NULL)
00130                 parms[0] = ltype;
00131         else {
00132                 p = parms[0];
00133                 while(*p) *p++ = tolower(*p);
00134                 strncpy(ltype, parms[0], sizeof(ltype));
00135         }
00136         s = 0;
00137         if(!strcmp(parms[0], "mtype")) s = domtype(parms, np);
00138         else
00139         if(!strcmp(parms[0], "vhost")) s = dovhost(parms, np);
00140         else
00141         if(!strcmp(parms[0], "vpath")) s = dovpath(parms, np);
00142         else
00143         if(!strcmp(parms[0], "serverroot")) s = dosrvrroot(parms, np);
00144         else
00145         if(!strcmp(parms[0], "dirsend")) s = dodirsend(parms, np);
00146         else
00147         if(!strcmp(parms[0], "direxec")) s = dodirexec(parms, np);
00148         else
00149         if(!strcmp(parms[0], "logfile")) s = dologfile(parms, np);
00150         else
00151         if(!strcmp(parms[0], "dbgfile")) s = dodbgfile(parms, np);
00152         else
00153         if(!strcmp(parms[0], "user")) s = douser(parms, np);
00154         else
00155         if(!strcmp(parms[0], "chroot")) s = dochroot(parms, np);
00156         else
00157         if(!strcmp(parms[0], "auth")) s = doauth(parms, np);
00158         else
00159         if(!strcmp(parms[0], "proxyauth")) s = doproxyauth(parms, np);
00160         else
00161         if(!strcmp(parms[0], "include")) s = doinclude(parms, np);
00162         else
00163         fprintf(stderr, "httpd: Unknown directive: %s\n", parms[0]);
00164         if(s) {
00165                 fprintf(stderr, "httpd: Error processing config file\n");
00166                 fclose(fp);
00167                 return(-1);
00168         }
00169    }
00170 
00171    fclose(fp);
00172 
00173    return(0);
00174 }
00175 
00176 static int doinclude(parms, np)
00177 char *parms[];
00178 int np;
00179 {
00180 char *p;
00181 
00182    if(np < 2) return(0);
00183 
00184    p = subvpath(parms[1]);
00185 
00186    return(doconfig(p));
00187 }
00188 
00189 static int domtype(parms, np)
00190 char *parms[];
00191 int np;
00192 {
00193 int i;
00194 struct mtype *pt, *lpt, *newpt;
00195 struct msufx *ps, *lps, *newps, *psend;
00196 
00197    if(np < 2) return(0);
00198 
00199 
00200    /* check if this mime type already exists in the list */
00201    for(pt = mtype, lpt = NULL; pt != NULL; lpt = pt, pt = pt->next)
00202         if(!strcmp(parms[1], pt->mimetype))
00203                 break;
00204 
00205    if(pt == NULL) {             /* not there so add it */
00206         newpt = malloc(sizeof(struct mtype));
00207         if(newpt == NULL) {
00208                 fprintf(stderr, "httpd: malloc failed in domtype\n");
00209                 return(-1);
00210         }
00211         newpt->mimetype = malloc(strlen(parms[1])+1);
00212         if(newpt->mimetype == NULL) {
00213                 fprintf(stderr, "httpd: malloc failed in domtype\n");
00214                 return(-1);
00215         }
00216         strcpy(newpt->mimetype, parms[1]);
00217         newpt->msufx = NULL;
00218         newpt->next = NULL;
00219         if(lpt == NULL)
00220                 mtype = newpt;
00221         else
00222                 lpt->next = newpt;
00223    } else
00224         newpt = pt;
00225 
00226    /* find end of suffix list */
00227    for(ps = newpt->msufx, lps = NULL; ps != NULL; lps = ps, ps = ps->tnext) ;
00228    psend = lps;
00229 
00230    /* if no suffix given then add empty suffix for default */
00231    if(np == 2)
00232         strcpy(parms[np++], "");
00233 
00234    /* add each suffix to the mime type */
00235    for(i = 2; i < np; i++) {
00236         /* a suffix can only be for a single mime type */
00237         for(ps = msufx, lps = NULL; ps != NULL; lps = ps, ps = ps->snext) {
00238                 if(!strcmp(ps->suffix, parms[i])) {
00239                         fprintf(stderr, "httpd: Suffix already found\n");
00240                         return(-1);
00241                 }
00242                 if(strlen(parms[i]) > strlen(ps->suffix)) break;
00243         }
00244         newps = malloc(sizeof(struct msufx));
00245         if(newps == NULL) {
00246                 fprintf(stderr, "httpd: malloc failed in domtype\n");
00247                 return(-1);
00248         }
00249         newps->suffix = malloc(strlen(parms[i])+1);
00250         if(newps->suffix == NULL) {
00251                 fprintf(stderr, "httpd: malloc failed in domtype\n");
00252                 return(-1);
00253         }
00254         strcpy(newps->suffix, parms[i]);
00255         newps->mtype = newpt;
00256         newps->snext = NULL;
00257         newps->tnext = NULL;
00258         if(lps == NULL) {
00259                 msufx = newps;
00260                 newps->snext = ps;
00261         } else {
00262                 lps->snext = newps;
00263                 newps->snext = ps;
00264         }
00265         if(psend == NULL)
00266                 newpt->msufx = newps;
00267         else
00268                 psend->tnext = newps;
00269         psend = newps;
00270    }
00271 
00272    return(0);
00273 }
00274 
00275 static struct auth *findauth(name)
00276 char *name;
00277 {
00278 char lname[80];
00279 char *p, *p2;
00280 struct auth *a = NULL;
00281 
00282    if(sizeof(lname) < (strlen(name)+1)) {
00283         fprintf(stderr, "httpd: lname too small in findauth\n");
00284         return(a);
00285    }
00286    p = name; p2 = lname;
00287    while(*p)
00288         *p2++ = tolower(*p++);
00289    *p2 = '\0';
00290 
00291    for(a = auth; a != NULL; a = a->next)
00292         if(!strcmp(a->name, lname)) break;
00293 
00294    return(a);
00295 }
00296 
00297 static int dovhost(parms, np)
00298 char *parms[];
00299 int np;
00300 {
00301 char *hname, *root;
00302 struct vhost *ph, *lph, *newph;
00303 
00304    if(np < 2) return(0);
00305 
00306    hname = parms[1];
00307 
00308    if(np < 3)
00309         root = "";
00310    else
00311         root = parms[2];
00312 
00313    for(ph = vhost, lph = NULL; ph != NULL; lph = ph, ph = ph->next)
00314         ;
00315 
00316    newph = malloc(sizeof(struct vhost));
00317    if(newph == NULL) {
00318         fprintf(stderr, "httpd: malloc failed in dovhost\n");
00319         return(-1);
00320    }
00321    newph->hname = malloc(strlen(hname)+1);
00322    if(newph->hname == NULL) {
00323         fprintf(stderr, "httpd: malloc failed in dovhost\n");
00324         return(-1);
00325    }
00326    strcpy(newph->hname, hname);
00327 
00328    root = subvpath(root);
00329 
00330    newph->root = malloc(strlen(root)+1);
00331    if(newph->root == NULL) {
00332         fprintf(stderr, "httpd: malloc failed in dovhost\n");
00333         return(-1);
00334    }
00335    strcpy(newph->root, root);
00336 
00337    if(np > 3)
00338         if(parms[3][0] != '#') {
00339                 fprintf(stderr, "httpd: junk at end of vhost line\n");
00340                 return(-1);
00341         }
00342 
00343    newph->next = NULL;
00344    if(lph == NULL) {
00345         vhost = newph;
00346         newph->next = ph;
00347    } else {
00348         lph->next = newph;
00349         newph->next = ph;
00350    }
00351 
00352    return(0);
00353 }
00354 
00355 static int dovpath(parms, np)
00356 char *parms[];
00357 int np;
00358 {
00359 char *from, *to;
00360 struct vpath *pv, *lpv, *newpv;
00361 
00362    if(np < 3) return(0);
00363 
00364    from = parms[1];
00365    to = parms[2];
00366 
00367    for(pv = vpath, lpv = NULL; pv != NULL; lpv = pv, pv = pv->next)
00368         ;
00369 
00370    newpv = malloc(sizeof(struct vpath));
00371    if(newpv == NULL) {
00372         fprintf(stderr, "httpd: malloc failed in dovpath\n");
00373         return(-1);
00374    }
00375    newpv->from = malloc(strlen(from)+1);
00376    if(newpv->from == NULL) {
00377         fprintf(stderr, "httpd: malloc failed in dovpath\n");
00378         return(-1);
00379    }
00380    strcpy(newpv->from, from);
00381 
00382    to = subvpath(to);
00383 
00384    newpv->to = malloc(strlen(to)+1);
00385    if(newpv->to == NULL) {
00386         fprintf(stderr, "httpd: malloc failed in dovpath\n");
00387         return(-1);
00388    }
00389    strcpy(newpv->to, to);
00390 
00391    newpv->auth = NULL;
00392    newpv->urlaccess = -1;
00393 
00394    if(np > 3)
00395         if(parms[3][0] != '#') {
00396                 newpv->auth = findauth(parms[3]);
00397                 if(np > 4)
00398                         if(parms[4][0] != '#') {
00399                                 newpv->urlaccess = mkurlaccess(parms[4]);
00400                                 if(np > 5)
00401                                         if(parms[5][0] != '#') {
00402                                                 fprintf(stderr, "httpd: junk at end of vpath line\n");
00403                                                 return(-1);
00404                                         }
00405                         }
00406         }
00407 
00408    newpv->next = NULL;
00409    if(lpv == NULL) {
00410         vpath = newpv;
00411         newpv->next = pv;
00412    } else {
00413         lpv->next = newpv;
00414         newpv->next = pv;
00415    }
00416 
00417    return(0);
00418 }
00419 
00420 static int dosrvrroot(parms, np)
00421 char *parms[];
00422 int np;
00423 {
00424 char *newroot;
00425 
00426    if(np < 2) return(0);
00427 
00428    newroot = subvpath(parms[1]);
00429 
00430    srvrroot = malloc(strlen(newroot)+1);
00431    if(srvrroot == NULL) {
00432         fprintf(stderr, "httpd: malloc failed in dosrvrroot\n");
00433         return(-1);
00434    }
00435    strcpy(srvrroot, newroot);
00436    if(srvrroot[strlen(srvrroot)-1] == '/')
00437         srvrroot[strlen(srvrroot)-1] = '\0';
00438 
00439    return(0);
00440 }
00441 
00442 static int dodirsend(parms, np)
00443 char *parms[];
00444 int np;
00445 {
00446 char *file;
00447 int i;
00448 struct dirsend *pd, *lpd, *npd;
00449 
00450    if(np < 2) return(0);
00451 
00452    /* find end of the list */
00453    for(pd = dirsend, lpd = NULL; pd != NULL; lpd = pd, pd = pd->next) ;
00454 
00455    for(i = 1; i < np; i++) {
00456         file = parms[i];
00457         if(file[0] == '#') break;
00458         npd = malloc(sizeof(struct dirsend));
00459         if(npd == NULL) {
00460                 fprintf(stderr, "httpd: malloc failed in dodirsend\n");
00461                 return(-1);
00462         }
00463         npd->file = malloc(strlen(file)+1);
00464         if(npd->file == NULL) {
00465                 fprintf(stderr, "httpd: malloc failed in dodirsend\n");
00466                 return(-1);
00467         }
00468         strcpy(npd->file, file);
00469         npd->next = NULL;
00470         if(lpd == NULL)
00471                 dirsend = npd;
00472         else
00473                 lpd->next = npd;
00474         lpd = npd;
00475    }
00476 
00477    return(0);
00478 }
00479 
00480 static int dodirexec(parms, np)
00481 char *parms[];
00482 int np;
00483 {
00484 char *file;
00485 
00486    if(np < 2) return(0);
00487 
00488    if(direxec != NULL) {
00489         fprintf(stderr, "httpd: Error direxec line already present\n");
00490         return(-1);
00491    }
00492 
00493    file = subvpath(parms[1]);
00494 
00495    direxec = malloc(strlen(file)+1);
00496 
00497    if(direxec == NULL) {
00498         fprintf(stderr, "httpd: malloc failed in dodirexec\n");
00499         return(-1);
00500    }
00501 
00502    strcpy(direxec, file);
00503 
00504    if(np > 2)
00505         if(parms[2][0] != '#') {
00506                 fprintf(stderr, "httpd: garbage on end of direxec line\n");
00507                 return(-1);
00508         }
00509 
00510    return(0);
00511 }
00512 
00513 static char *subvpath(s)
00514 char *s;
00515 {
00516 char *p, *p2;
00517 int len;
00518 static char buffer[1024];
00519 char user[80];
00520 struct passwd *pwd;
00521 
00522    /* replace beginning // with srvrroot */
00523    if(s[0] == '/' && s[1] == '/')
00524         /* but not /// if we have VHOST's */
00525         if(vhost == NULL || s[2] != '/') {
00526                 strcpy(buffer, srvrroot);
00527                 strncat(buffer, s+1, sizeof(buffer) - strlen(buffer));
00528                 buffer[sizeof(buffer)-1] = '\0';
00529                 return(buffer);
00530         }
00531 
00532    if(s[0] != '/' || s[1] != '~') return(s);
00533 
00534    /* replace beginning /~user with user home directory */
00535    p = s + 2;
00536    p2 = user;
00537    len = sizeof(user) - 1;
00538    while(*p && *p != '/' && len-- > 0) *p2++ = *p++;
00539    *p2 = '\0';
00540    if(*p != '\0' && *p != '/') return(s);
00541    if((pwd = getpwnam(user)) == (struct passwd *)NULL) return(s);
00542    strcpy(buffer, pwd->pw_dir);
00543    strncat(buffer, p, sizeof(buffer) - strlen(buffer));
00544    buffer[sizeof(buffer)-1] = '\0';
00545 
00546    return(buffer);
00547 }
00548 
00549 static int dologfile(parms, np)
00550 char *parms[];
00551 int np;
00552 {
00553 char *p;
00554 
00555    if(np < 2) return(0);
00556 
00557    p = subvpath(parms[1]);
00558    LogFile = malloc(strlen(p)+1);
00559    if(LogFile == NULL) {
00560         fprintf(stderr, "httpd: malloc failed in dologfile\n");
00561         return(-1);
00562    }
00563    strcpy(LogFile, p);
00564 
00565    return(0);
00566 }
00567 
00568 static int dodbgfile(parms, np)
00569 char *parms[];
00570 int np;
00571 {
00572 char *p;
00573 
00574    if(np < 2) return(0);
00575 
00576    p = subvpath(parms[1]);
00577    DbgFile = malloc(strlen(p)+1);
00578    if(DbgFile == NULL) {
00579         fprintf(stderr, "httpd: malloc failed in dodbgfile\n");
00580         return(-1);
00581    }
00582    strcpy(DbgFile, p);
00583 
00584    return(0);
00585 }
00586 
00587 static int douser(parms, np)
00588 char *parms[];
00589 int np;
00590 {
00591    if(np < 2) return(0);
00592 
00593    User = malloc(strlen(parms[1])+1);
00594    if(User == NULL) {
00595         fprintf(stderr, "httpd: malloc failed in douser\n");
00596         return(-1);
00597    }
00598    strcpy(User, parms[1]);
00599 
00600    return(0);
00601 }
00602 
00603 static int dochroot(parms, np)
00604 char *parms[];
00605 int np;
00606 {
00607 char *newroot;
00608 
00609    if(np < 2) return(0);
00610 
00611    newroot = subvpath(parms[1]);
00612 
00613    Chroot = malloc(strlen(newroot)+1);
00614    if(Chroot == NULL) {
00615         fprintf(stderr, "httpd: malloc failed in dochroot\n");
00616         return(-1);
00617    }
00618    strcpy(Chroot, newroot);
00619 
00620    return(0);
00621 }
00622 
00623 static int adduser(pauth, user)
00624 struct auth *pauth;
00625 char *user;
00626 {
00627 struct authuser *pa, *lpa, *newpa;
00628 
00629    for(pa = pauth->users, lpa = NULL; pa != NULL; lpa = pa, pa = pa->next)
00630         ;
00631 
00632    newpa = malloc(sizeof(struct authuser));
00633    if(newpa == NULL) {
00634         fprintf(stderr, "httpd: malloc failed in adduser\n");
00635         return(-1);
00636    }
00637    newpa->user = malloc(strlen(user)+1);
00638    if(newpa->user == NULL) {
00639         fprintf(stderr, "httpd: malloc failed in adduser\n");
00640         return(-1);
00641    }
00642    strcpy(newpa->user, user);
00643 
00644    newpa->next = NULL;
00645    if(lpa == NULL) {
00646         pauth->users = newpa;
00647         newpa->next = pa;
00648    } else {
00649         lpa->next = newpa;
00650         newpa->next = pa;
00651    }
00652 
00653    return(0);
00654 }
00655 
00656 static int doauth(parms, np)
00657 char *parms[];
00658 int np;
00659 {
00660 int i;
00661 char *name, *desc, *pf;
00662 char *p, *p2;
00663 struct auth *pa, *lpa, *newpa;
00664 
00665    if(np < 3) return(0);
00666 
00667    name = parms[1];
00668    desc = parms[2];
00669 
00670    for(pa = auth, lpa = NULL; pa != NULL; lpa = pa, pa = pa->next)
00671         ;
00672 
00673    newpa = malloc(sizeof(struct auth));
00674    if(newpa == NULL) {
00675         fprintf(stderr, "httpd: malloc failed in doauth\n");
00676         return(-1);
00677    }
00678    newpa->name = malloc(strlen(name)+1);
00679    if(newpa->name == NULL) {
00680         fprintf(stderr, "httpd: malloc failed in doauth\n");
00681         return(-1);
00682    }
00683    p = name; p2 = newpa->name;
00684    while(*p)
00685         *p2++ = tolower(*p++);
00686    *p2 = '\0';
00687 
00688    newpa->desc = malloc(strlen(desc)+1);
00689    if(newpa->desc == NULL) {
00690         fprintf(stderr, "httpd: malloc failed in doauth\n");
00691         return(-1);
00692    }
00693    strcpy(newpa->desc, desc);
00694 
00695    newpa->urlaccess = mkurlaccess(parms[3]);
00696    newpa->passwdfile = NULL;
00697    newpa->users = NULL;
00698 
00699    if(np > 4)
00700         if(parms[4][0] != '#') {
00701                 if(!strcmp(parms[4], "."))
00702                         pf = "/etc/passwd";
00703                 else
00704                         pf = subvpath(parms[4]);
00705                 newpa->passwdfile = malloc(strlen(pf)+1);
00706                 if(newpa->passwdfile == NULL) {
00707                         fprintf(stderr, "httpd: malloc failed in doauth\n");
00708                         return(-1);
00709                 }
00710                 strcpy(newpa->passwdfile, pf);
00711                 i = 5;
00712                 while(i < np) {
00713                         if(parms[i][0] == '#')
00714                                 break;
00715                         if(adduser(newpa, parms[i]))
00716                                 return(-1);
00717                         i++;
00718                 }
00719         }
00720 
00721    newpa->next = NULL;
00722    if(lpa == NULL) {
00723         auth = newpa;
00724         newpa->next = pa;
00725    } else {
00726         lpa->next = newpa;
00727         newpa->next = pa;
00728    }
00729 
00730    return(0);
00731 }
00732 
00733 static int doproxyauth(parms, np)
00734 char *parms[];
00735 int np;
00736 {
00737 int i;
00738 char *name, *desc, *pf;
00739 char *p, *p2;
00740 struct auth *pa, *lpa, *newpa;
00741 
00742    if(np < 3) return(0);
00743 
00744    name = parms[1];
00745    desc = parms[2];
00746 
00747    if(proxyauth != (struct auth *)NULL) {
00748         fprintf(stderr, "httpd: ProxyAuth defined multiple times using 1st only\n");
00749         return(0);
00750    }
00751 
00752    for(pa = proxyauth, lpa = NULL; pa != NULL; lpa = pa, pa = pa->next)
00753         ;
00754 
00755    newpa = malloc(sizeof(struct auth));
00756    if(newpa == NULL) {
00757         fprintf(stderr, "httpd: malloc failed in doproxyauth\n");
00758         return(-1);
00759    }
00760    newpa->name = malloc(strlen(name)+1);
00761    if(newpa->name == NULL) {
00762         fprintf(stderr, "httpd: malloc failed in doproxyauth\n");
00763         return(-1);
00764    }
00765    p = name; p2 = newpa->name;
00766    while(*p)
00767         *p2++ = tolower(*p++);
00768    *p2 = '\0';
00769 
00770    newpa->desc = malloc(strlen(desc)+1);
00771    if(newpa->desc == NULL) {
00772         fprintf(stderr, "httpd: malloc failed in doproxyauth\n");
00773         return(-1);
00774    }
00775    strcpy(newpa->desc, desc);
00776 
00777    newpa->urlaccess = mkurlaccess(parms[3]);
00778    newpa->passwdfile = NULL;
00779    newpa->users = NULL;
00780 
00781    if(np > 4)
00782         if(parms[4][0] != '#') {
00783                 if(!strcmp(parms[4], "."))
00784                         pf = "/etc/passwd";
00785                 else
00786                         pf = subvpath(parms[4]);
00787                 newpa->passwdfile = malloc(strlen(pf)+1);
00788                 if(newpa->passwdfile == NULL) {
00789                         fprintf(stderr, "httpd: malloc failed in doauth\n");
00790                         return(-1);
00791                 }
00792                 strcpy(newpa->passwdfile, pf);
00793                 i = 5;
00794                 while(i < np) {
00795                         if(parms[i][0] == '#')
00796                                 break;
00797                         if(adduser(newpa, parms[i]))
00798                                 return(-1);
00799                         i++;
00800                 }
00801         }
00802 
00803    newpa->next = NULL;
00804    if(lpa == NULL) {
00805         proxyauth = newpa;
00806         newpa->next = pa;
00807    } else {
00808         lpa->next = newpa;
00809         newpa->next = pa;
00810    }
00811 
00812    return(0);
00813 }

Generated on Fri Apr 14 22:56:54 2006 for minix by  doxygen 1.4.6