[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

off-topic program-Q



Hi,

as the subject says, this is really off-topic. But I still hope that 
somebody can help me.

I have the following piece of code (stripped down):


if (fetch) {
	pid = fork();

	if (!pid) {
		printf("Global newsgroupdescription-file is out of date.\n");
		printf("Getting new one in background.\n");
		setgid(egid);
		sprintf(buff, "%s/tmpdsc", SLRN_DSC_DIR);
		if (execl("/bin/sh", "-c", "/usr/bin/slrn.real", "-f", buff,
					"-d", NULL) != -1) {
			sprintf(buff, "%s/tmpdsc.dsc", SLRN_DSC_DIR);
			sprintf(buff2, "%s/newsgroups.dsc", SLRN_DSC_DIR);
			execl("/bin/mv", buff, buff2);
		} else {
			perror(NULL);
		}
		run=0;
	}
}

if (run) {
	sprintf(buff, "%s/locked", SLRN_DSC_DIR);
	unlink(buff);
	setegid(gid);
	execv("/usr/bin/slrn.real", argv);
	printf("\n");
}

This program is setgid news. The directory in which it is supposed to 
write is group news and mode g=rs. The part that is executed in the 
parent- process runs well (the last if()), including the execv. However, 
the part insode the 'if (!pid)' fails on the execl. In the form you see 
it here it complains it can't execute /usr/bin/slrn.real (I use sh -c 
here cos ultimately I want to redirect output to /dev/null). If I leave 
the '/bin/sh -c', it fails in opening /var/lib/slrn/tmpdsc.dsc (which is 
opened by slrn.real).

I also tried this in perl, where it failed, even after fooling around 
with GID's and EGID's, so I thought I'd give C a try, but to no avail sofar.

Anybody knows what I'm doing wrong? I'd like to get this working...

Maarten

_______________________________________________________________________
| Maarten Boekhold, Faculty of Electrical Engineering TU Delft,   NL  |
|   boekhold@cindy.et.tudelft.nl boekhold@gopher.library.tudelft.nl   |
|                  Take life as a party!                              |
-----------------------------------------------------------------------


Reply to: