... | ... |
@@ -2,6 +2,7 @@ $Id$ |
2 | 2 |
|
3 | 3 |
( - todo, x - done) |
4 | 4 |
|
5 |
+ |
|
5 | 6 |
- fix parse_cseq!!! (it doesnt parse 1234\n INVITE a.s.o) |
6 | 7 |
x fix 0 parameter module f. call |
7 | 8 |
x better Via parsing (handle ' ' in uri, eg: foo.bar : 1234 ; received=) and |
... | ... |
@@ -21,6 +22,8 @@ x plugin interface |
21 | 22 |
- add User-Agent (for the replies) |
22 | 23 |
|
23 | 24 |
Low priority: |
25 |
+- add support for -u user and -g group (not only -u uid, -g uid) |
|
26 |
+- change uid/gid after opening the sockets |
|
24 | 27 |
- exec improvments (add format strings to it) |
25 | 28 |
- command line switch for checking the config file syntax |
26 | 29 |
- config file version (a la sendmail) |
... | ... |
@@ -110,7 +110,11 @@ Options:\n\ |
110 | 110 |
-V Version number\n\ |
111 | 111 |
-h This help message\n\ |
112 | 112 |
-b nr Maximum receive buffer size which will not be exceeded by\n\ |
113 |
- auto-probing procedure even if OS allows\n" |
|
113 |
+ auto-probing procedure even if OS allows\n\ |
|
114 |
+ -w dir change the working directory to \"dir\" (default \"/\")\n\ |
|
115 |
+ -t dir chroot to \"dir\"\n\ |
|
116 |
+ -u uid change uid \n\ |
|
117 |
+ -g gid change gid \n" |
|
114 | 118 |
#ifdef STATS |
115 | 119 |
" -s file File to which statistics is dumped (disabled otherwise)\n" |
116 | 120 |
#endif |
... | ... |
@@ -159,6 +163,10 @@ int check_via = 0; /* check if reply first via host==us */ |
159 | 163 |
int loop_checks = 0; /* calculate branches and check for loops/spirals */ |
160 | 164 |
int received_dns = 0; /* use dns and/or rdns or to see if we need to |
161 | 165 |
add a ;received=x.x.x.x to via: */ |
166 |
+char* working_dir = 0; |
|
167 |
+char* chroot_dir = 0; |
|
168 |
+int uid = 0; |
|
169 |
+int gid = 0; |
|
162 | 170 |
|
163 | 171 |
char* names[MAX_LISTEN]; /* our names */ |
164 | 172 |
int names_len[MAX_LISTEN]; /* lengths of the names*/ |
... | ... |
@@ -194,11 +202,27 @@ int daemonize(char* name) |
194 | 202 |
openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/); |
195 | 203 |
/* LOG_CONS, LOG_PERRROR ? */ |
196 | 204 |
|
197 |
- if (chdir("/")<0){ |
|
198 |
- LOG(L_CRIT,"cannot chroot:%s\n", strerror(errno)); |
|
205 |
+ |
|
206 |
+ if (chroot_dir&&(chroot(chroot_dir)<0)){ |
|
207 |
+ LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno)); |
|
199 | 208 |
goto error; |
200 | 209 |
} |
201 | 210 |
|
211 |
+ if (chdir(working_dir)<0){ |
|
212 |
+ LOG(L_CRIT,"cannot chdir to %s: %s\n", working_dir, strerror(errno)); |
|
213 |
+ goto error; |
|
214 |
+ } |
|
215 |
+ |
|
216 |
+ if (gid&&(setgid(gid)<0)){ |
|
217 |
+ LOG(L_CRIT, "cannot change gid to %d: %s\n", gid, strerror(errno)); |
|
218 |
+ goto error; |
|
219 |
+ } |
|
220 |
+ |
|
221 |
+ if(uid&&(setuid(uid)<0)){ |
|
222 |
+ LOG(L_CRIT, "cannot change uid to %d: %s\n", uid, strerror(errno)); |
|
223 |
+ goto error; |
|
224 |
+ } |
|
225 |
+ |
|
202 | 226 |
/* fork to become!= group leader*/ |
203 | 227 |
if ((pid=fork())<0){ |
204 | 228 |
LOG(L_CRIT, "Cannot fork:%s\n", strerror(errno)); |
... | ... |
@@ -437,7 +461,7 @@ int main(int argc, char** argv) |
437 | 461 |
#ifdef STATS |
438 | 462 |
"s:" |
439 | 463 |
#endif |
440 |
- "f:p:b:l:n:rRvcdDEVh"; |
|
464 |
+ "f:p:b:l:n:rRvcdDEVhw:t:u:g:"; |
|
441 | 465 |
|
442 | 466 |
while((c=getopt(argc,argv,options))!=-1){ |
443 | 467 |
switch(c){ |
... | ... |
@@ -521,6 +545,27 @@ int main(int argc, char** argv) |
521 | 545 |
printf("%s",help_msg); |
522 | 546 |
exit(0); |
523 | 547 |
break; |
548 |
+ case 'w': |
|
549 |
+ working_dir=optarg; |
|
550 |
+ break; |
|
551 |
+ case 't': |
|
552 |
+ chroot_dir=optarg; |
|
553 |
+ break; |
|
554 |
+ case 'u': |
|
555 |
+ uid=strtol(optarg, &tmp, 10); |
|
556 |
+ if ((tmp==0) ||(*tmp)){ |
|
557 |
+ fprintf(stderr, "bad uid number: -u %s\n", optarg); |
|
558 |
+ goto error; |
|
559 |
+ } |
|
560 |
+ /* test if string?*/ |
|
561 |
+ break; |
|
562 |
+ case 'g': |
|
563 |
+ gid=strtol(optarg, &tmp, 10); |
|
564 |
+ if ((tmp==0) ||(*tmp)){ |
|
565 |
+ fprintf(stderr, "bad gid number: -g %s\n", optarg); |
|
566 |
+ goto error; |
|
567 |
+ } |
|
568 |
+ break; |
|
524 | 569 |
case '?': |
525 | 570 |
if (isprint(optopt)) |
526 | 571 |
fprintf(stderr, "Unknown option `-%c�.\n", optopt); |
... | ... |
@@ -598,6 +643,8 @@ int main(int argc, char** argv) |
598 | 643 |
MAX_PROCESSES-1 ); |
599 | 644 |
goto error; |
600 | 645 |
} |
646 |
+ |
|
647 |
+ if (working_dir==0) working_dir="/"; |
|
601 | 648 |
/*alloc pids*/ |
602 | 649 |
#ifdef SHM_MEM |
603 | 650 |
pids=shm_malloc(sizeof(int)*children_no); |