/* cfuserid.c */ /* Copyright 1997-2000 by Eberhard Mattes Donated to the public domain. No warranty. 1997-01-04 Initial version 1997-04-05 Reorganize library 1997-07-24 Add prototype for mapuid() 2000-04-29 set_userid_groupid() 2000-05-27 Use config_arg_count() */ #include #include #include #include #include #include "firewall.h" #include "libemfw.h" /* firewall.h lacks some declarations. */ extern int mapuid (char *); int libemfw_uid = -1; int config_userid (Cfg *confp, int do_set) { Cfg *cf; int uid; if ((cf = cfg_get ("userid", confp)) == (Cfg *)0) return -1; config_arg_count (cf, 1); if ((uid = mapuid (cf->argv[0])) == -1) { syslog (LLEV, "fwtkcfgerr: cannot map %s to uid", cf->argv[0]); exit (1); } if (!do_set) libemfw_uid = uid; /* do_fastdaemon() and set_userid_groupid() */ else if (setuid (uid) != 0) { syslog (LLEV, "fwtksyserr: cannot setuid %d: %s", uid, strerror(errno)); exit (1); } return uid; }