Browse code

*** empty log message ***

Andrei Pelinescu-Onciul authored on 22/01/2002 22:33:42
Showing 2 changed files
... ...
@@ -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 21
 - add User-Agent (for the replies)
22 22
 
23 23
 Low priority:
24
+- add support for -u user and -g group (not only -u uid, -g uid)
25
+- change uid/gid after opening the sockets
24 26
 - exec improvments (add format strings to it)
25 27
 - command line switch for checking the config file syntax
26 28
 - 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 159
 int loop_checks = 0;	/* calculate branches and check for loops/spirals */
160 160
 int received_dns = 0;      /* use dns and/or rdns or to see if we need to 
161 161
                               add a ;received=x.x.x.x to via: */
162
+char* working_dir = 0;
163
+char* chroot_dir = 0;
164
+int uid = 0;
165
+int gid = 0;
162 166
 
163 167
 char* names[MAX_LISTEN];               /* our names */
164 168
 int names_len[MAX_LISTEN];    /* lengths of the names*/
... ...
@@ -194,11 +202,27 @@ int daemonize(char*  name)
194 194
 		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);
195 195
 		/* LOG_CONS, LOG_PERRROR ? */
196 196
 
197
-	if (chdir("/")<0){
198
-		LOG(L_CRIT,"cannot chroot:%s\n", strerror(errno));
197
+
198
+	if (chroot_dir&&(chroot(chroot_dir)<0)){
199
+		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
199 200
 		goto error;
200 201
 	}
201 202
 	
203
+	if (chdir(working_dir)<0){
204
+		LOG(L_CRIT,"cannot chdir to %s: %s\n", working_dir, strerror(errno));
205
+		goto error;
206
+	}
207
+
208
+	if (gid&&(setgid(gid)<0)){
209
+		LOG(L_CRIT, "cannot change gid to %d: %s\n", gid, strerror(errno));
210
+		goto error;
211
+	}
212
+	
213
+	if(uid&&(setuid(uid)<0)){
214
+		LOG(L_CRIT, "cannot change uid to %d: %s\n", uid, strerror(errno));
215
+		goto error;
216
+	}
217
+
202 218
 	/* fork to become!= group leader*/
203 219
 	if ((pid=fork())<0){
204 220
 		LOG(L_CRIT, "Cannot fork:%s\n", strerror(errno));
... ...
@@ -437,7 +461,7 @@ int main(int argc, char** argv)
437 437
 #ifdef STATS
438 438
 	"s:"
439 439
 #endif
440
-	"f:p:b:l:n:rRvcdDEVh";
440
+	"f:p:b:l:n:rRvcdDEVhw:t:u:g:";
441 441
 	
442 442
 	while((c=getopt(argc,argv,options))!=-1){
443 443
 		switch(c){
... ...
@@ -521,6 +545,27 @@ int main(int argc, char** argv)
521 521
 					printf("%s",help_msg);
522 522
 					exit(0);
523 523
 					break;
524
+			case 'w':
525
+					working_dir=optarg;
526
+					break;
527
+			case 't':
528
+					chroot_dir=optarg;
529
+					break;
530
+			case 'u':
531
+					uid=strtol(optarg, &tmp, 10);
532
+					if ((tmp==0) ||(*tmp)){
533
+						fprintf(stderr, "bad uid number: -u %s\n", optarg);
534
+						goto error;
535
+					}
536
+					/* test if string?*/
537
+					break;
538
+			case 'g':
539
+					gid=strtol(optarg, &tmp, 10);
540
+					if ((tmp==0) ||(*tmp)){
541
+						fprintf(stderr, "bad gid number: -g %s\n", optarg);
542
+						goto error;
543
+					}
544
+					break;
524 545
 			case '?':
525 546
 					if (isprint(optopt))
526 547
 						fprintf(stderr, "Unknown option `-%c�.\n", optopt);
... ...
@@ -598,6 +643,8 @@ int main(int argc, char** argv)
598 598
 			MAX_PROCESSES-1 );
599 599
 		goto error;
600 600
 	}
601
+	
602
+	if (working_dir==0) working_dir="/";
601 603
 	/*alloc pids*/
602 604
 #ifdef SHM_MEM
603 605
 	pids=shm_malloc(sizeof(int)*children_no);