From 4544c87c6355037a095e296b5280ccb3ff25ac4b Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 24 Jan 1998 19:14:04 +0000 Subject: [PATCH] RJK fixes. --- Changelog | 10 ++++++++-- client.c | 1 + parser.c | 20 +++++++++++++------- process.c | 3 +++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Changelog b/Changelog index 11b83d7..5e0c49e 100644 --- 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 Sat, 24 Jan 1998 19:13:34 +0000 userv (0.57); urgency=high diff --git a/client.c b/client.c index bc55412..f53211f 100644 --- 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"); diff --git a/parser.c b/parser.c index 898bbfa..0505474 100644 --- 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; diff --git a/process.c b/process.c index 9f6fbc0..b091f4e 100644 --- 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; } } } -- 2.30.2