chiark / gitweb /
RJK fixes.
authorian <ian>
Sat, 24 Jan 1998 19:14:04 +0000 (19:14 +0000)
committerian <ian>
Sat, 24 Jan 1998 19:14:04 +0000 (19:14 +0000)
Changelog
client.c
parser.c
process.c

index 11b83d7924bc47644c2b29e71fec15f906b05f64..5e0c49e0c784015f18ff93436f72322fb5e9515b 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,9 +1,15 @@
-userv (0.57.1); urgency=high
+userv (0.58); urgency=high
 
+  * Fixed failure to set gid when invoking service !!
+  * Fixed failure to set fd value in et_closereadfd messages from client.
+
+  * Save filename string in parse_file for error reporting (in case it is
+    overwritten by parsing code).
+  * Fixed obscure race in process.c:getevent (et_closereadfd and hold fds).
   * `builtin version' service had error message and errno string reserve
     values exchanged.
 
- --
+ -- Ian Jackson <ian@davenant.greenend.org.uk>  Sat, 24 Jan 1998 19:13:34 +0000
 
 userv (0.57); urgency=high
 
index bc554128cff66cadc40098d6d4e2566edd2a2428..f53211fd310a0295135bd5b1288f2cc59cf14f40 100644 (file)
--- a/client.c
+++ b/client.c
@@ -378,6 +378,7 @@ static void sighandler_chld(int ignored) /* DOES return, unlike in daemon */ {
        memset(&event_mbuf,0,sizeof(event_mbuf));
        event_mbuf.magic= EVENT_MAGIC;
        event_mbuf.type= et_closereadfd;
+        event_mbuf.data.closereadfd.fd= fd;
        r= fwrite(&event_mbuf,1,sizeof(event_mbuf),swfile);
        if (r != sizeof(event_mbuf) || fflush(swfile))
          if (errno != EPIPE) syscallerror("inform service of closed read fd");
index 898bbfac2c3f2f0d9e1d8ac6e3d2ba1cfd0092fa..0505474cf8e244cef09af0e12e215681f09733cc 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1235,8 +1235,10 @@ static void parser_pop(void) {
 }
 
 int parse_string(const char *string, const char *descrip, int isinternal) {
-  /* Returns the same things as parser, except that tokv_eof
-   * is turned into 0.
+  /* Returns the same things as parser, except that tokv_eof is turned
+   * into 0.  *string must be statically allocated or copied, so that
+   * it is not overwritten while the parsing takes place (unlike with
+   * parse_file).
    */
   static const struct stat blankstab;
   
@@ -1256,9 +1258,10 @@ int parse_string(const char *string, const char *descrip, int isinternal) {
 }
 
 static int parse_file(const char *string, int *didexist) {
-  /* Returns the same things as parser, except that tokv_eof
-   * is turned into 0.  If *didexist is 0 then errno will
-   * have been set.
+  /* Returns the same things as parser, except that tokv_eof is turned
+   * into 0.  If *didexist is 0 then errno will have been set.
+   * *string will be copied by parse_file so it may be be overwritten
+   * during the parsing (so, for example, yytext need not be copied).
    */
   static int fileparselevel= 0;
   
@@ -1266,6 +1269,7 @@ static int parse_file(const char *string, int *didexist) {
   YY_BUFFER_STATE ybuf;
   int r;
   FILE *file;
+  char *filename;
   struct stat newstab;
 
   if (fileparselevel >= MAX_INCLUDE_NEST) {
@@ -1294,9 +1298,10 @@ static int parse_file(const char *string, int *didexist) {
   
   if (didexist) *didexist= 1;
 
+  filename= xstrsave(string);
   ybuf= yy_create_buffer(file,YY_BUF_SIZE);
   if (!ybuf) syscallerror("unable to create flex buffer for file");
-  parser_push(&usestate,string,&newstab,ybuf,0);
+  parser_push(&usestate,filename,&newstab,ybuf,0);
   fileparselevel++;
   
   r= parser(0);
@@ -1304,9 +1309,10 @@ static int parse_file(const char *string, int *didexist) {
     parseerrprint("error reading configuration file `%s'",string);
     r= tokv_error;
   }
-  
+
   fileparselevel--;
   parser_pop();
+  free(filename);
   fclose(file);
   if (r == tokv_eof) r= 0;
   return r;
index 9f6fbc0b946fa7ed9965e48db2c4ac03bb59abd3..b091f4e5b8876b490f6159eb0a0f071eac07a51d 100644 (file)
--- a/process.c
+++ b/process.c
@@ -507,6 +507,7 @@ static void lookup_uidsgids(void) {
   serviceuser_shell= xstrsave(pw->pw_shell);
   serviceuser_uid= pw->pw_uid;
   
+  if (setregid(pw->pw_gid,pw->pw_gid)) syscallerror("setregid 1");
   if (initgroups(pw->pw_name,pw->pw_gid)) syscallerror("initgroups");
   if (setreuid(pw->pw_uid,pw->pw_uid)) syscallerror("setreuid 1");
   if (setreuid(pw->pw_uid,pw->pw_uid)) syscallerror("setreuid 2");
@@ -514,6 +515,7 @@ static void lookup_uidsgids(void) {
     if (!setreuid(pw->pw_uid,0)) miscerror("setreuid 3 unexpectedly succeeded");
     if (errno != EPERM) syscallerror("setreuid 3 failed in unexpected way");
   }
+  if (setregid(pw->pw_gid,pw->pw_gid)) syscallerror("setregid 2");
 
   service_ngids= getgroups(0,0); if (service_ngids == -1) syscallerror("getgroups(0,0)");
   if (service_ngids > MAX_GIDS) miscerror("service user is in far too many groups");
@@ -597,6 +599,7 @@ static void makenonexistentfd(int fd) {
     if (fdarray[fd].holdfd != -1) {
       if (close(fdarray[fd].holdfd))
        syscallfailure("close unwanted hold descriptor for %d",fd);
+      fdarray[fd].holdfd= -1;
     }
   }
 }