--- server/misc.c.orig Wed Aug 8 02:04:13 2001 +++ server/misc.c Wed Aug 8 02:05:00 2001 @@ -46,11 +46,12 @@ #include #endif #ifdef __EMX__ -#include #include #endif #include +#include #include +#include #include "IR.h" #include "net.h" @@ -87,6 +88,8 @@ int MMountFlag = 0; /* メモリに辞書をロードするかしないかのフラグ */ static char Name[64]; +static char *userID=NULL; /* canna server's user id */ + #ifdef USE_INET_SOCKET /* flag for using INET Domain Socket */ #ifdef USE_UNIX_SOCKET @@ -110,7 +113,7 @@ static void Reset(); static void parQUIT(); -#define USAGE "Usage: cannaserver [-p num] [-l num] [-syslog] [-inet] [-d] [dichome]" +#define USAGE "Usage: cannaserver [-p num] [-l num] [-u userid] [-syslog] [-inet] [-d] [dichome]" static void Usage() { @@ -128,6 +131,7 @@ char buf[ MAXDATA ]; int parent, parentid, i; int context; + struct passwd *pwent; strcpy( Name, argv[ 0 ] ); @@ -148,6 +152,16 @@ /* NOTREACHED */ } } + else if( !strcmp( argv[i], "-u")) { + if (++i < argc) { + userID = argv[i]; + } + else { + fprintf(stderr, "%s\n", USAGE); + exit(2); + /* NOTREACHED */ + } + } #ifdef USE_INET_SOCKET else if( !strcmp( argv[i], "-inet")) { UseInet = 1; @@ -182,6 +196,23 @@ if( !ddname ) FatalError("cannaserver:Initialize failed\n"); strcpy( (char *)ddname, DICHOME ); + } + + if (userID != NULL) { + pwent = getpwnam(userID); + if (pwent) { + if(setgid(pwent->pw_gid)) { + FatalError("cannaserver:couldn't set groupid to canna user's group\n"); + } + if (initgroups(userID, pwent->pw_gid)) { + FatalError("cannserver: couldn't init supplementary groups\n"); + } + if (setuid(pwent->pw_uid)) { + FatalError("cannaserver: couldn't set userid to %s user\n", userID); + } + } else if (userID != NULL) { + FatalError("cannaserver: -u flag specified, but canna not run as root\n"); + } } #ifdef DEBUG