summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Steves <stevesk@pobox.com>2001-01-14 00:35:19 +0000
committerKevin Steves <stevesk@pobox.com>2001-01-14 00:35:19 +0000
commit886b06ce67f9fda0121ec4a3875970bc2316e780 (patch)
tree8a6a34933214016240fe1b75407ef99d775c44be
parent2f959b4cd1d1afcd241d7ffa06a34646c0c89969 (diff)
- (stevesk) initial work for OpenBSD "support supplementary group in
{Allow,Deny}Groups" patch: - import getgrouplist.c from OpenBSD (bsd-getgrouplist.c) - add bsd-getgrouplist.h - new files groupaccess.[ch] - build but don't use yet (need to merge auth.c changes)
-rw-r--r--ChangeLog8
-rw-r--r--Makefile.in4
-rw-r--r--bsd-getgrouplist.c103
-rw-r--r--bsd-getgrouplist.h14
-rw-r--r--configure.in2
-rw-r--r--groupaccess.c76
-rw-r--r--groupaccess.h47
-rw-r--r--openbsd-compat.h1
8 files changed, 252 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a92eb1c8..072cb4c2d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
120010114
2 - (stevesk) initial work for OpenBSD "support supplementary group in
3 {Allow,Deny}Groups" patch:
4 - import getgrouplist.c from OpenBSD (bsd-getgrouplist.c)
5 - add bsd-getgrouplist.h
6 - new files groupaccess.[ch]
7 - build but don't use yet (need to merge auth.c changes)
8
120010112 920010112
2 - (bal) OpenBSD Sync 10 - (bal) OpenBSD Sync
3 - markus@cvs.openbsd.org 2001/01/10 22:56:22 11 - markus@cvs.openbsd.org 2001/01/10 22:56:22
diff --git a/Makefile.in b/Makefile.in
index c22d5eff8..1080f26ec 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -39,11 +39,11 @@ TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keys
39 39
40LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o cygwin_util.o deattack.o dispatch.o hmac.o hostfile.o key.o kex.o log.o match.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o util.o uuencode.o xmalloc.o 40LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o cygwin_util.o deattack.o dispatch.o hmac.o hostfile.o key.o kex.o log.o match.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o util.o uuencode.o xmalloc.o
41 41
42LIBOPENBSD_COMPAT_OBJS=bsd-arc4random.o bsd-base64.o bsd-bindresvport.o bsd-daemon.o bsd-getcwd.o bsd-inet_aton.o bsd-inet_ntoa.o bsd-misc.o bsd-mktemp.o bsd-realpath.o bsd-rresvport.o bsd-setenv.o bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o bsd-strtok.o bsd-vis.o bsd-setproctitle.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o next-posix.o 42LIBOPENBSD_COMPAT_OBJS=bsd-arc4random.o bsd-base64.o bsd-bindresvport.o bsd-daemon.o bsd-getcwd.o bsd-getgrouplist.o bsd-inet_aton.o bsd-inet_ntoa.o bsd-misc.o bsd-mktemp.o bsd-realpath.o bsd-rresvport.o bsd-setenv.o bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o bsd-strtok.o bsd-vis.o bsd-setproctitle.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o next-posix.o
43 43
44SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o 44SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o
45 45
46SSHDOBJS= sshd.o auth.o auth1.o auth2.o auth-skey.o auth2-skey.o auth-rhosts.o auth-options.o auth-krb4.o auth-pam.o auth2-pam.o auth-passwd.o auth-rsa.o auth-rh-rsa.o dh.o pty.o log-server.o login.o loginrec.o servconf.o serverloop.o md5crypt.o session.o 46SSHDOBJS= sshd.o auth.o auth1.o auth2.o auth-skey.o auth2-skey.o auth-rhosts.o auth-options.o auth-krb4.o auth-pam.o auth2-pam.o auth-passwd.o auth-rsa.o auth-rh-rsa.o dh.o pty.o log-server.o login.o loginrec.o servconf.o serverloop.o md5crypt.o session.o groupaccess.o
47 47
48TROFFMAN = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 48TROFFMAN = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8
49CATMAN = scp.0 ssh-add.0 ssh-agent.0 ssh-keygen.0 ssh-keyscan.0 ssh.0 sshd.0 sftp-server.0 49CATMAN = scp.0 ssh-add.0 ssh-agent.0 ssh-keygen.0 ssh-keyscan.0 ssh.0 sshd.0 sftp-server.0
diff --git a/bsd-getgrouplist.c b/bsd-getgrouplist.c
new file mode 100644
index 000000000..f7a27c339
--- /dev/null
+++ b/bsd-getgrouplist.c
@@ -0,0 +1,103 @@
1/*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include "includes.h"
35
36#ifndef HAVE_GETGROUPLIST
37
38#if defined(LIBC_SCCS) && !defined(lint)
39static char rcsid[] = "$OpenBSD: getgrouplist.c,v 1.7 1997/08/19 19:13:27 deraadt Exp $";
40#endif /* LIBC_SCCS and not lint */
41
42/*
43 * get credential
44 */
45#include <sys/types.h>
46#include <string.h>
47#include <grp.h>
48
49int
50getgrouplist(uname, agroup, groups, grpcnt)
51 const char *uname;
52 gid_t agroup;
53 register gid_t *groups;
54 int *grpcnt;
55{
56 register struct group *grp;
57 register int i, ngroups;
58 int ret, maxgroups;
59 int bail;
60
61 ret = 0;
62 ngroups = 0;
63 maxgroups = *grpcnt;
64
65 /*
66 * install primary group
67 */
68 if (ngroups >= maxgroups) {
69 *grpcnt = ngroups;
70 return (-1);
71 }
72 groups[ngroups++] = agroup;
73
74 /*
75 * Scan the group file to find additional groups.
76 */
77 setgrent();
78 while ((grp = getgrent())) {
79 if (grp->gr_gid == agroup)
80 continue;
81 for (bail = 0, i = 0; bail == 0 && i < ngroups; i++)
82 if (groups[i] == grp->gr_gid)
83 bail = 1;
84 if (bail)
85 continue;
86 for (i = 0; grp->gr_mem[i]; i++) {
87 if (!strcmp(grp->gr_mem[i], uname)) {
88 if (ngroups >= maxgroups) {
89 ret = -1;
90 goto out;
91 }
92 groups[ngroups++] = grp->gr_gid;
93 break;
94 }
95 }
96 }
97out:
98 endgrent();
99 *grpcnt = ngroups;
100 return (ret);
101}
102
103#endif /* HAVE_GETGROUPLIST */
diff --git a/bsd-getgrouplist.h b/bsd-getgrouplist.h
new file mode 100644
index 000000000..ef9e60116
--- /dev/null
+++ b/bsd-getgrouplist.h
@@ -0,0 +1,14 @@
1#ifndef _BSD_GETGROUPLIST_H
2#define _BSD_GETGROUPLIST_H
3
4#include "config.h"
5
6#ifndef HAVE_GETGROUPLIST
7
8#include <grp.h>
9
10int getgrouplist(const char *, gid_t, gid_t *, int *);
11
12#endif
13
14#endif
diff --git a/configure.in b/configure.in
index 7f1d2af2d..1ee188565 100644
--- a/configure.in
+++ b/configure.in
@@ -316,7 +316,7 @@ AC_CHECK_FUNC(utimes,
316AC_CHECK_HEADERS(bstring.h endian.h floatingpoint.h getopt.h lastlog.h limits.h login.h login_cap.h maillock.h netdb.h netgroup.h netinet/in_systm.h paths.h poll.h pty.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/queue.h sys/select.h sys/stat.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h sys/un.h stddef.h time.h ttyent.h usersec.h util.h utmp.h utmpx.h vis.h) 316AC_CHECK_HEADERS(bstring.h endian.h floatingpoint.h getopt.h lastlog.h limits.h login.h login_cap.h maillock.h netdb.h netgroup.h netinet/in_systm.h paths.h poll.h pty.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/queue.h sys/select.h sys/stat.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h sys/un.h stddef.h time.h ttyent.h usersec.h util.h utmp.h utmpx.h vis.h)
317 317
318dnl Checks for library functions. 318dnl Checks for library functions.
319AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_af clock fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getnameinfo getrlimit getrusage getttyent inet_aton inet_ntoa innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv seteuid setlogin setproctitle setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strsep strtok_r sysconf vsnprintf vhangup vis waitpid _getpty __b64_ntop) 319AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_af clock fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent inet_aton inet_ntoa innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv seteuid setlogin setproctitle setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strsep strtok_r sysconf vsnprintf vhangup vis waitpid _getpty __b64_ntop)
320dnl Checks for time functions 320dnl Checks for time functions
321AC_CHECK_FUNCS(gettimeofday time) 321AC_CHECK_FUNCS(gettimeofday time)
322dnl Checks for libutil functions 322dnl Checks for libutil functions
diff --git a/groupaccess.c b/groupaccess.c
new file mode 100644
index 000000000..bf6be997e
--- /dev/null
+++ b/groupaccess.c
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) 2001 Kevin Steves. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26
27#include "groupaccess.h"
28#include "ssh.h"
29#include "xmalloc.h"
30#include "match.h"
31
32static int ngroups;
33static char *groups_byname[NGROUPS_MAX + 1]; /* +1 for base/primary group */
34
35int
36ga_init(const char *user, gid_t base)
37{
38 gid_t groups_bygid[NGROUPS_MAX + 1];
39 int i, j;
40 struct group *gr;
41
42 if (ngroups > 0)
43 ga_free();
44
45 ngroups = sizeof(groups_bygid) / sizeof(gid_t);
46 if (getgrouplist(user, base, groups_bygid, &ngroups) == -1)
47 log("getgrouplist: groups list too small");
48 for (i = 0, j = 0; i < ngroups; i++)
49 if ((gr = getgrgid(groups_bygid[i])) != NULL)
50 groups_byname[j++] = xstrdup(gr->gr_name);
51 return (ngroups = j);
52}
53
54int
55ga_match(char * const *groups, int n)
56{
57 int i, j;
58
59 for (i = 0; i < ngroups; i++)
60 for (j = 0; j < n; j++)
61 if (match_pattern(groups_byname[i], groups[j]))
62 return 1;
63 return 0;
64}
65
66void
67ga_free(void)
68{
69 int i;
70
71 if (ngroups > 0) {
72 for (i = 0; i < ngroups; i++)
73 xfree(groups_byname[i]);
74 ngroups = 0;
75 }
76}
diff --git a/groupaccess.h b/groupaccess.h
new file mode 100644
index 000000000..7e8584bde
--- /dev/null
+++ b/groupaccess.h
@@ -0,0 +1,47 @@
1/*
2 * Copyright (c) 2001 Kevin Steves. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#ifndef GROUPACCESS_H
26#define GROUPACCESS_H
27
28#include <grp.h>
29
30/*
31 * Initialize group access list for user with primary (base) and
32 * supplementary groups. Return the number of groups in the list.
33 */
34int ga_init(const char *user, gid_t base);
35
36/*
37 * Return 1 if one of user's groups is contained in groups.
38 * Return 0 otherwise. Use match_pattern() for string comparison.
39 */
40int ga_match(char * const *groups, int ngroups);
41
42/*
43 * Free memory allocated for group access list.
44 */
45void ga_free(void);
46
47#endif
diff --git a/openbsd-compat.h b/openbsd-compat.h
index 1be0ccd40..9213bead5 100644
--- a/openbsd-compat.h
+++ b/openbsd-compat.h
@@ -24,6 +24,7 @@
24#include "bsd-vis.h" 24#include "bsd-vis.h"
25#include "bsd-waitpid.h" 25#include "bsd-waitpid.h"
26#include "bsd-setproctitle.h" 26#include "bsd-setproctitle.h"
27#include "bsd-getgrouplist.h"
27 28
28/* rfc2553 socket API replacements */ 29/* rfc2553 socket API replacements */
29#include "fake-getaddrinfo.h" 30#include "fake-getaddrinfo.h"