Problem with getuid() -- same as geteuid()?!
Maarten Litmaath
maart at cs.vu.nl
Wed Feb 7 02:38:41 AEST 1990
In article <1837 at clyde.concordia.ca>,
smw at maxwell.Concordia.CA ( Steven Winikoff ) writes:
\In article <?_3}%- at rpi.edu> tale at cs.rpi.edu (David C Lawrence) writes:
\
\>@opinionated sidebar
\>I personally loathe getlogin() and programmes that are concerned with
\>what userid I might have started out as on some pre-su level, [...]
\...
\My problem is that there are several people at our site who are legitimately
\able to su root, working on different projects at the same time (perhaps
\that's a bad idea, but it's not under my control). In any case, the idea
\is to find some way to identify our printed output, [...]
But that's precisely what UCB's lpr does! By means of getlogin()! :-(
Anyway, you could always replace lpr by something like this:
#include <pwd.h>
#include <stdio.h>
char My_lpr[] = "/path/of/my_lpr";
main(argc, argv)
int argc;
char **argv;
{
char *getenv(), *lprname = getenv("LPRNAME");
struct passwd *pw;
if (lprname) {
if (!(pw = getpwnam(lprname)))
fprintf(stderr,
"You don't exist. Go away.\n");
else if (setuid(pw->pw_uid) != 0)
perror("setuid");
}
argv[0] = My_lpr;
execv(My_lpr, argv);
perror(My_lpr);
exit(1);
}
...where `my_lpr' is:
#!/bin/sh
exec 3>&1
test -t 0 && exec < /dev/null
(/usr/ucb/lpr ${1+"$@"} | cat >&3) 2>&1 | cat >&2
--
The meek get the earth, Henry the moon, the rest of us have other plans. |
Maarten Litmaath @ VU Amsterdam: maart at cs.vu.nl, uunet!mcsun!botter!maart
More information about the Comp.unix.questions
mailing list