Back to index

courier  0.68.2
webadmin.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2001-2006 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include <stdio.h>
00007 #include <unistd.h>
00008 #include <pwd.h>
00009 #include <grp.h>
00010 #include <stdlib.h>
00011 #include <unistd.h>
00012 #include <string.h>
00013 #include "config.h"
00014 
00015 
00016 int main()
00017 {
00018        struct group *g;
00019        struct passwd *p;
00020 
00021        const char *c=getenv("PATH_INFO");
00022        int isroot=0;
00023 
00024        if (c)
00025        {
00026               if (*c == '/')
00027                      ++c;
00028               if (strcmp(c, "save") == 0)
00029                      isroot=1;
00030        }
00031 
00032        if (isroot)
00033               setuid(0);
00034        else
00035        {
00036               g=getgrnam(MAILGROUP);
00037               if (!g)
00038               {
00039                      printf("Content-Type: text/plain\n\ngetgrnam(%s) failed\n",
00040                             MAILGROUP);
00041                      exit(0);
00042               }
00043 
00044               setgid(g->gr_gid);
00045 
00046               p=getpwnam(MAILUSER);
00047               if (!p)
00048               {
00049                      printf("Content-Type: text/plain\n\ngetpwnam(%s) failed\n",
00050                             MAILUSER);
00051                      exit(0);
00052               }
00053               setuid(p->pw_uid);
00054        }
00055 
00056        execl(INSTDIR "/webadmin.pl", INSTDIR "/webadmin.pl", (char *)0);
00057        exit(0);
00058 }