--- src/p_global.h.old 2005-06-04 20:22:45.000000000 +0200 +++ src/p_global.h 2007-08-16 17:02:55.000000000 +0200 @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include --- src/psybnc.c.old 2005-06-04 20:22:45.000000000 +0200 +++ src/psybnc.c 2007-08-16 17:06:43.000000000 +0200 @@ -168,6 +168,9 @@ char *bversion; FILE *pidfile,*conffile; int i; + uid_t uid; + gid_t gid; + if(argc==2) { strmncpy(configfile,argv[1],sizeof(configfile)); @@ -182,6 +185,62 @@ } fclose(conffile); readconfig(); + + rc = getini("SYSTEM","USER",INIFILE); + if (rc==0) + { + struct passwd *user; + user=(struct passwd *)getpwnam(value); + if (user!=NULL) + { + uid=user->pw_uid; + } + else + { + printf("WARNING: UNIX user %s does not exist.\n", value); + } + } + rc = getini("SYSTEM","GROUP",INIFILE); + if (rc==0) + { + struct group *group; + group=(struct group *)getgrnam(value); + if (group!=NULL) + { + gid=group->gr_gid; + } + else + { + printf("WARNING: UNIX group %s does not exist.\n", value); + } + } + if ((uid!=NULL) && (gid!=NULL)) + { + if ((geteuid()!=0) && (getegid()!=0)) + { + struct passwd *user; + struct group *group; + user=(struct passwd *)getpwuid(geteuid()); + group=(struct group *)getgrgid(getegid()); + printf("WARNING: unable to change privileges, not running as root. PsyBNC will run as %s:%s instead.\n",user->pw_name,group->gr_name); + } + else + { + setuid(uid); + setgid(gid); + } + } + + rc = getini("SYSTEM","ROOTDIR",INIFILE); + if (rc==0) + { + if (chdir(value)!=0) + { + printf("Unable to change working directory to %s\n", value); + exit (0x0); + } + } + rc = getini("SYSTEM","LANGUAGE",INIFILE); /* rcsid */ if(rc!=0) { @@ -232,7 +291,15 @@ exit (0x0); } /* creating background */ - pidfile = fopen(lngtxt(1003),"w"); + rc = getini("SYSTEM","PIDFILE",INIFILE); + if (rc==0) + { + pidfile = fopen(value,"w"); + } + else if ((rc!=0) || (pidfile==NULL)) + { + pidfile = fopen(lngtxt(1003),"w"); + } if(pidfile==NULL) { printf(lngtxt(1004));