]> git.pld-linux.org Git - packages/arpd.git/blob - arpd-uid.patch
- fixed obsolete rc-script macros
[packages/arpd.git] / arpd-uid.patch
1 --- ./arpd.c.orig       Tue Aug 21 13:26:27 2001
2 +++ ./arpd.c    Fri Aug 24 12:28:12 2001
3 @@ -21,6 +21,7 @@
4  #include <sys/socket.h>
5  #include <netinet/in.h>
6  #include <arpa/inet.h>
7 +#include <pwd.h>
8  
9  #ifdef DEBUG
10  static void arpd_print(char*, struct arpd_request*);
11 @@ -28,10 +29,25 @@
12  #define arpd_print(x,y) 
13  #endif
14  
15 -/* these shouldn't change for ipv4 */
16 +/* these shouldn't change for ipv4     */
17  #define ARPD_TRIEWIDTH 256
18  #define ARPD_TRIEDEPTH 16
19  
20 +/* usage string                                */
21 +static char* usage=
22 +"ARP daemon - version 1.0.2 - PLD modified
23 +Usage: arpd -u user
24 +-u             user, which you want to run this deamon
25 +
26 +The user you will take must have RW access to /dev/arpd.
27 +If you don't know what to choice take root.
28 +
29 +";
30 +
31 +void show_usage() {
32 +       fprintf(stdout,usage);
33 +}
34 +
35  union arpd_triedef
36  {
37         union arpd_triedef * hash;
38 @@ -54,7 +70,34 @@
39         struct arpd_request req;
40         struct arpd_request *rep;
41  
42 +       char* cmd = NULL;
43 +       unsigned int uid_num = 0;
44 +       struct passwd *pw;
45 +       char *account;
46 +
47 +if ((argc != 3)) {
48 +       fprintf(stdout,"Invalid option.\n");
49 +       show_usage();
50 +       exit(1);
51 +       }
52 +else {
53  #ifndef DEBUG
54 +       cmd = argv[1];
55 +
56 +       if (strcasecmp(cmd, "-u") == 0) {
57 +               account=argv[2];
58 +               pw=getpwnam(account);
59 +               if (!pw) {
60 +                       fprintf(stderr,"Unknown account.\n");
61 +                       exit(1);
62 +               }
63 +               uid_num=pw->pw_uid;
64 +       }
65 +       else {
66 +               fprintf(stderr,"Invalid option.\n");
67 +               show_usage();
68 +               exit(1);
69 +       }
70         if (fork())
71                 exit(0);
72  
73 @@ -72,14 +115,19 @@
74                 if (fd > 2)
75                         close(fd);
76         }
77 -       setsid();
78 +       /* setsid(); */
79 +       
80  #endif
81  
82         openlog ("arpd", LOG_PID | LOG_CONS, LOG_DAEMON);
83  
84 -       syslog(LOG_NOTICE, "Initializing, version %s\n", ARPD_VERSION);
85 +       syslog(LOG_NOTICE, "Initializing, modified version %s\n", ARPD_VERSION);
86  
87         fd = open("/dev/arpd", O_RDWR);
88 +
89 +       /* Set proper UID */
90 +       setuid(uid_num);
91 +
92         if (fd < 0) {
93                 syslog(LOG_CRIT, "cannot open /dev/arpd: %m");
94                 exit(-1);
95 @@ -136,6 +184,7 @@
96         }
97  
98         return 0;
99 +       }
100  }
101  
102  static void arpd_update (struct arpd_request * entry)
This page took 0.040135 seconds and 3 git commands to generate.