--- ./arpd.c.orig Tue Aug 21 13:26:27 2001 +++ ./arpd.c Fri Aug 24 12:28:12 2001 @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef DEBUG static void arpd_print(char*, struct arpd_request*); @@ -28,10 +29,25 @@ #define arpd_print(x,y) #endif -/* these shouldn't change for ipv4 */ +/* these shouldn't change for ipv4 */ #define ARPD_TRIEWIDTH 256 #define ARPD_TRIEDEPTH 16 +/* usage string */ +static char* usage= +"ARP daemon - version 1.0.2 - PLD modified\n\ +Usage: arpd -u user\n\ +-u user, which you want to run this deamon\n\ +\n\ +The user you will take must have RW access to /dev/arpd.\n\ +If you don't know what to choice take root.\n\ +\n\ +"; + +void show_usage() { + fprintf(stdout,usage); +} + union arpd_triedef { union arpd_triedef * hash; @@ -54,7 +70,34 @@ struct arpd_request req; struct arpd_request *rep; + char* cmd = NULL; + unsigned int uid_num = 0; + struct passwd *pw; + char *account; + +if ((argc != 3)) { + fprintf(stdout,"Invalid option.\n"); + show_usage(); + exit(1); + } +else { #ifndef DEBUG + cmd = argv[1]; + + if (strcasecmp(cmd, "-u") == 0) { + account=argv[2]; + pw=getpwnam(account); + if (!pw) { + fprintf(stderr,"Unknown account.\n"); + exit(1); + } + uid_num=pw->pw_uid; + } + else { + fprintf(stderr,"Invalid option.\n"); + show_usage(); + exit(1); + } if (fork()) exit(0); @@ -72,14 +115,19 @@ if (fd > 2) close(fd); } - setsid(); + /* setsid(); */ + #endif openlog ("arpd", LOG_PID | LOG_CONS, LOG_DAEMON); - syslog(LOG_NOTICE, "Initializing, version %s\n", ARPD_VERSION); + syslog(LOG_NOTICE, "Initializing, modified version %s\n", ARPD_VERSION); fd = open("/dev/arpd", O_RDWR); + + /* Set proper UID */ + setuid(uid_num); + if (fd < 0) { syslog(LOG_CRIT, "cannot open /dev/arpd: %m"); exit(-1); @@ -136,6 +184,7 @@ } return 0; + } } static void arpd_update (struct arpd_request * entry)