home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume1
/
8706
/
6
< prev
next >
Wrap
Text File
|
1993-09-01
|
2KB
|
78 lines
Article 86 of comp.sources.misc:
Relay-Version: version B 2.10.3 alpha 5/22/85; site osu-eddie.UUCP
Path: osu-eddie!cbosgd!ihnp4!ptsfa!ames!necntc!ncoast!allbery
From: jfh@killer.UUCP (John Haugh)
Newsgroups: comp.sources.misc
Subject: Setgrp - spawn a process into a new group
Message-ID: <2738@ncoast.UUCP>
Date: 29 Jun 87 00:47:41 GMT
Date-Received: 29 Jun 87 20:13:40 GMT
Sender: allbery@ncoast.UUCP
Lines: 60
Keywords: newgrp
Approved: allbery@ncoast.UUCP
X-Archive: comp.sources.misc/8706/6
I wrote this to handle a problem that a poster asked about in
comp.unix.questions. Hope you like it as much as we do. Must
be run set-uid (boo) and probably is only useful on System V.
Basically, the program checks the /etc/group file and sees
if you are in the group. Probably not totally sexure, mostly
because it ignores passwords! But then its free ...
- john.
------------------------- cut here ----------------------
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
struct passwd *getpwuid ();
struct group *getgrnam ();
main (argc, argv)
int argc;
char **argv;
{
char username[20];
char groupname[20];
struct passwd *ppwd;
struct group *pgrp;
int i;
if (argc < 3) {
fprintf (stderr, "usage: %s group command [ args ... ]\n", arg[0]);
exit (1);
}
if (! (ppwd = getpwuid (getuid ()))) {
fprintf (stderr, "Error reading password file\n");
exit (1);
}
strncpy (username, ppwd->pw_name, sizeof (username));
strncpy (groupname, argv[1], sizeof (groupname));
if (! (pgrp = getgrnam (groupname))) {
fprintf (stderr, "Nonexistent group: %s\n", groupname);
exit (1);
}
for (i = 0;pgrp->gr_mem[i] != (char *) 0;i++) {
if (strncmp (username, pgrp->gr_mem[i], sizeof (username)))
continue;
else
break;
}
if (pgrp->gr_mem[i] == (char *) 0) {
fprintf (stderr, "Permission denied\n");
exit (1);
}
setgid (pgrp->gr_gid);
setuid (getuid ());
execvp (argv[2], &argv[2]);
perror (argv[2]);
exit (1);
}