]> andersk Git - openssh.git/blobdiff - groupaccess.c
- (dtucker) [sftp.c] Expand ifdef for libedit to cover complete_is_remote
[openssh.git] / groupaccess.c
index f50879f83a9fae7b0a72514b5d2cb72024cd7119..2381aeb15b57edf4deefacd0084ba5697a522149 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: groupaccess.c,v 1.13 2008/07/04 03:44:59 djm Exp $ */
 /*
  * Copyright (c) 2001 Kevin Steves.  All rights reserved.
  *
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: groupaccess.c,v 1.6 2003/04/08 20:21:28 itojun Exp $");
 
-#include "groupaccess.h"
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <grp.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <string.h>
+
 #include "xmalloc.h"
+#include "groupaccess.h"
 #include "match.h"
 #include "log.h"
 
@@ -52,8 +60,8 @@ ga_init(const char *user, gid_t base)
        ngroups = MAX(NGROUPS_MAX, sysconf(_SC_NGROUPS_MAX));
 #endif
 
-       groups_bygid = xmalloc(ngroups * sizeof(*groups_bygid));
-       groups_byname = xmalloc(ngroups * sizeof(*groups_byname));
+       groups_bygid = xcalloc(ngroups, sizeof(*groups_bygid));
+       groups_byname = xcalloc(ngroups, sizeof(*groups_byname));
 
        if (getgrouplist(user, base, groups_bygid, &ngroups) == -1)
                logit("getgrouplist: groups list too small");
@@ -80,6 +88,30 @@ ga_match(char * const *groups, int n)
        return 0;
 }
 
+/*
+ * Return 1 if one of user's groups matches group_pattern list.
+ * Return 0 on negated or no match.
+ */
+int
+ga_match_pattern_list(const char *group_pattern)
+{
+       int i, found = 0;
+       size_t len = strlen(group_pattern);
+
+       for (i = 0; i < ngroups; i++) {
+               switch (match_pattern_list(groups_byname[i],
+                   group_pattern, len, 0)) {
+               case -1:
+                       return 0;       /* Negated match wins */
+               case 0:
+                       continue;
+               case 1:
+                       found = 1;
+               }
+       }
+       return found;
+}
+
 /*
  * Free memory allocated for group access list.
  */
This page took 0.394383 seconds and 4 git commands to generate.