aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@openbsd.org>2015-07-30 17:04:33 +0000
committerTed Unangst <tedu@openbsd.org>2015-07-30 17:04:33 +0000
commit82ed45022baa7e6aa2a84a7a6f8ab83c882167cf (patch)
tree4a309c4ce22bf5df616c5b0a05c487570f32eaa9
parentf9adeee96e41896c1ff8504c0c7c6f6f96fad067 (diff)
downloadopendoas-82ed45022baa7e6aa2a84a7a6f8ab83c882167cf.tar.gz
make gid parsing look like uid parsing. from Martijn van Duren
ack deraadt
-rw-r--r--doas.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/doas.c b/doas.c
index 5fd53c0..7a525e6 100644
--- a/doas.c
+++ b/doas.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: doas.c,v 1.31 2015/07/28 21:36:03 deraadt Exp $ */
+/* $OpenBSD: doas.c,v 1.32 2015/07/29 00:00:31 tedu Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
@@ -80,19 +80,20 @@ uidcheck(const char *s, uid_t desired)
return 0;
}
-static gid_t
-strtogid(const char *s)
+static int
+parsegid(const char *s, gid_t *gid)
{
struct group *gr;
const char *errstr;
- gid_t gid;
- if ((gr = getgrnam(s)) != NULL)
- return gr->gr_gid;
- gid = strtonum(s, 0, GID_MAX, &errstr);
+ if ((gr = getgrnam(s)) != NULL) {
+ *gid = gr->gr_gid;
+ return 0;
+ }
+ *gid = strtonum(s, 0, GID_MAX, &errstr);
if (errstr)
return -1;
- return gid;
+ return 0;
}
static int
@@ -102,8 +103,8 @@ match(uid_t uid, gid_t *groups, int ngroups, uid_t target, const char *cmd,
int i;
if (r->ident[0] == ':') {
- gid_t rgid = strtogid(r->ident + 1);
- if (rgid == -1)
+ gid_t rgid;
+ if (parsegid(r->ident + 1, &rgid) == -1)
return 0;
for (i = 0; i < ngroups; i++) {
if (rgid == groups[i])