Update to 4.4-Lite version.
This commit is contained in:
parent
2c009d6038
commit
fedcc257c7
@ -1,5 +1,5 @@
|
||||
.\" Copyright (c) 1983, 1991 Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
@ -29,10 +29,10 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)initgroups.3 6.3 (Berkeley) 4/19/91
|
||||
.\" $Id: initgroups.3,v 1.2 1993/07/30 08:36:59 mycroft Exp $
|
||||
.\" from: @(#)initgroups.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $Id: initgroups.3,v 1.3 1994/09/19 07:50:52 mycroft Exp $
|
||||
.\"
|
||||
.Dd April 19, 1991
|
||||
.Dd June 4, 1993
|
||||
.Dt INITGROUPS 3
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@ -46,12 +46,13 @@
|
||||
The
|
||||
.Fn initgroups
|
||||
function
|
||||
reads through the group file and sets up,
|
||||
using the
|
||||
.Xr setgroups 2
|
||||
call, the group access list for the user
|
||||
uses the
|
||||
.Xr getgrouplist 3
|
||||
function to calculate the group access list for the user
|
||||
specified in
|
||||
.Fa name .
|
||||
This group list is then setup for the current process using
|
||||
.Xr setgroups 2 .
|
||||
The
|
||||
.Fa basegid
|
||||
is automatically included in the groups list.
|
||||
@ -62,12 +63,9 @@ The
|
||||
.Fn initgroups
|
||||
function
|
||||
returns \-1 if it was not invoked by the super-user.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /etc/group -compact
|
||||
.It Pa /etc/group
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr setgroups 2
|
||||
.Xr setgroups 2 ,
|
||||
.Xr getgrouplist 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
@ -75,8 +73,9 @@ function appeared in
|
||||
.Bx 4.2 .
|
||||
.Sh BUGS
|
||||
The
|
||||
.Fn initgroups
|
||||
function
|
||||
.Fn getgrouplist
|
||||
function called by
|
||||
.Nm
|
||||
uses the routines based on
|
||||
.Xr getgrent 3 .
|
||||
If the invoking program uses any of these routines,
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -32,57 +32,27 @@
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
/*static char *sccsid = "from: @(#)initgroups.c 5.7 (Berkeley) 2/23/91";*/
|
||||
static char *rcsid = "$Id: initgroups.c,v 1.4 1994/03/30 03:51:32 cgd Exp $";
|
||||
/*static char sccsid[] = "from: @(#)initgroups.c 8.1 (Berkeley) 6/4/93";*/
|
||||
static char *rcsid = "$Id: initgroups.c,v 1.5 1994/09/19 07:50:54 mycroft Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* initgroups
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <grp.h>
|
||||
|
||||
struct group *getgrent();
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
initgroups(uname, agroup)
|
||||
const char *uname;
|
||||
int agroup;
|
||||
{
|
||||
gid_t groups[NGROUPS];
|
||||
int ngroups = 0;
|
||||
register struct group *grp;
|
||||
register int i;
|
||||
int groups[NGROUPS], ngroups;
|
||||
|
||||
/*
|
||||
* If installing primary group, duplicate it;
|
||||
* the first element of groups is the effective gid
|
||||
* and will be overwritten when a setgid file is executed.
|
||||
*/
|
||||
if (agroup >= 0) {
|
||||
groups[ngroups++] = agroup;
|
||||
groups[ngroups++] = agroup;
|
||||
}
|
||||
setgrent();
|
||||
while (grp = getgrent()) {
|
||||
if (grp->gr_gid == agroup)
|
||||
continue;
|
||||
for (i = 0; grp->gr_mem[i]; i++)
|
||||
if (!strcmp(grp->gr_mem[i], uname)) {
|
||||
if (ngroups == NGROUPS) {
|
||||
fprintf(stderr, "initgroups: %s is in too many groups\n", uname);
|
||||
goto toomany;
|
||||
}
|
||||
groups[ngroups++] = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
toomany:
|
||||
endgrent();
|
||||
ngroups = NGROUPS;
|
||||
if (getgrouplist(uname, agroup, groups, &ngroups) < 0)
|
||||
warnx("%s is in too many groups, using first %d",
|
||||
uname, ngroups);
|
||||
if (setgroups(ngroups, groups) < 0) {
|
||||
perror("setgroups");
|
||||
warn("setgroups");
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user