[PATCH] Add setuidgid -s option, fix compile warnings and so on
SATOH Fumiyasu <[email protected]> Fri, 03 Sep 2010 20:33:16 +0900
| Newsgroups | gmane.comp.sysutils.bgware |
|---|---|
| Organization | OSS Technology, Inc. / Samba-JP / LDAP-JP / Apache-JP |
| Message-ID | <8762ynhxj7.wl%[email protected]> |
Hi, I wrote patchset for daemontools-encore 1.02. Please see the attached patches and apply it to the master git if you feel good. Regards, -- -- Name: SATOH Fumiyasu (fumiyas @ osstech co jp) -- Business Home: http://www.OSSTech.co.jp/ -- Personal Home: http://www.SFO.jp/blog/ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
0001-lock_ex.c-Include-unistd.h-for-lockf-3.patch
(application/octet-stream, 547 B)
From e13c6ba5944cc88985d4bbb7bca9c65d4b05b088 Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu <[email protected]> Date: Fri, 3 Sep 2010 20:24:42 +0900 Subject: [PATCH 1/5] lock_ex.c: Include unistd.h for lockf(3) --- lock_ex.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/lock_ex.c b/lock_ex.c index b75a764..a75ddaf 100644 --- a/lock_ex.c +++ b/lock_ex.c @@ -3,6 +3,7 @@ #include <sys/types.h> #include <sys/file.h> #include <fcntl.h> +#include <unistd.h> #include "hasflock.h" #include "lock.h" -- 1.7.1
0002-Use-uid_t-and-gid_t-for-UID-and-GID-numbers.patch
(application/octet-stream, 1.9 KB)
From ef7c1057c7da9ba165fbfda7fd859cb1e5971cb9 Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu <[email protected]> Date: Fri, 3 Sep 2010 20:26:51 +0900 Subject: [PATCH 2/5] Use uid_t and gid_t for UID and GID numbers --- installer.c | 18 ++++++++++++++---- prot.c | 4 ++-- prot.h | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/installer.c b/installer.c index 0b82375..ea714ca 100644 --- a/installer.c +++ b/installer.c @@ -32,8 +32,8 @@ void doit(stralloc *line) char *modestr; char *mid; char *name; - unsigned long uid; - unsigned long gid; + uid_t uid; + gid_t gid; unsigned long mode; int fdin; int fdout; @@ -74,8 +74,18 @@ void doit(stralloc *line) if (!stralloc_0(&target)) nomem(); if (xlen > 0) name = x; - uid = -1; if (*uidstr) scan_ulong(uidstr,&uid); - gid = -1; if (*gidstr) scan_ulong(gidstr,&gid); + uid = -1; + if (*uidstr) { + unsigned long uid_ul; + scan_ulong(uidstr,&uid_ul); + uid = (uid_t)uid_ul; + } + gid = -1; + if (*gidstr) { + unsigned long gid_ul; + scan_ulong(gidstr,&gid_ul); + gid = (gid_t)gid_ul; + } scan_8long(modestr,&mode); switch(*type) { diff --git a/prot.c b/prot.c index a617a53..73dbfed 100644 --- a/prot.c +++ b/prot.c @@ -5,7 +5,7 @@ #include "hasshsgr.h" #include "prot.h" -int prot_gid(int gid) +int prot_gid(gid_t gid) { #ifdef HASSHORTSETGROUPS short x[2]; @@ -17,7 +17,7 @@ int prot_gid(int gid) return setgid(gid); /* _should_ be redundant, but on some systems it isn't */ } -int prot_uid(int uid) +int prot_uid(uid_t uid) { return setuid(uid); } diff --git a/prot.h b/prot.h index 2e5cb81..9cfa612 100644 --- a/prot.h +++ b/prot.h @@ -3,7 +3,7 @@ #ifndef PROT_H #define PROT_H -extern int prot_gid(int); -extern int prot_uid(int); +extern int prot_gid(gid_t); +extern int prot_uid(uid_t); #endif -- 1.7.1
0003-.gitignore-Add-sleeper-and-tags.patch
(application/octet-stream, 583 B)
From 05891c0023ee519e97849d362307900b9de3ce48 Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu <[email protected]> Date: Fri, 3 Sep 2010 20:27:17 +0900 Subject: [PATCH 3/5] .gitignore: Add sleeper and tags --- .gitignore | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index ec78a65..e9dc530 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ rts-tmp select.h setlock setuidgid +sleeper softlimit supervise supervise.8 @@ -49,6 +50,7 @@ svup svup.8 sysdeps systype +tags tai64n tai64nlocal uint64.h -- 1.7.1
0004-rts.tests-Add-usr-ucb-to-PATH-to-find-printenv-1-on-.patch
(application/octet-stream, 743 B)
From ad0c88829a3b8a2ce45bbae771ec000528765b38 Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu <[email protected]> Date: Fri, 3 Sep 2010 20:27:47 +0900 Subject: [PATCH 4/5] rts.tests: Add /usr/ucb to $PATH to find printenv(1) on Solaris --- rts.tests/00-preamble.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rts.tests/00-preamble.sh b/rts.tests/00-preamble.sh index e435fb9..e5c3e8b 100644 --- a/rts.tests/00-preamble.sh +++ b/rts.tests/00-preamble.sh @@ -1,4 +1,4 @@ -PATH=`pwd`:/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin +PATH=`pwd`:/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/ucb export PATH umask 022 -- 1.7.1
0005-setuidgid-Add-s-option-to-set-account-s-supplementar.patch
(application/octet-stream, 2.7 KB)
From 2566eb49a0bb471e360b4495e5cc96591b48e48a Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu <[email protected]> Date: Fri, 3 Sep 2010 20:29:43 +0900 Subject: [PATCH 5/5] setuidgid: Add -s option to set account's supplementary gids --- prot.c | 5 +++++ prot.h | 1 + setuidgid.8 | 7 +++++++ setuidgid.c | 23 ++++++++++++++++++++--- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/prot.c b/prot.c index 73dbfed..e6b78a9 100644 --- a/prot.c +++ b/prot.c @@ -17,6 +17,11 @@ int prot_gid(gid_t gid) return setgid(gid); /* _should_ be redundant, but on some systems it isn't */ } +int prot_gids(const char *account, gid_t gid) +{ + return initgroups(account, gid); +} + int prot_uid(uid_t uid) { return setuid(uid); diff --git a/prot.h b/prot.h index 9cfa612..de15182 100644 --- a/prot.h +++ b/prot.h @@ -4,6 +4,7 @@ #define PROT_H extern int prot_gid(gid_t); +extern int prot_gids(const char *, gid_t); extern int prot_uid(uid_t); #endif diff --git a/setuidgid.8 b/setuidgid.8 index 78b79c9..547887a 100644 --- a/setuidgid.8 +++ b/setuidgid.8 @@ -3,6 +3,9 @@ setuidgid \- runs another program under a specified account's uid and gid. .SH SYNOPSIS .B setuidgid +[ +.B \-s +] .I account .I child .SH DESCRIPTION @@ -27,6 +30,10 @@ if it cannot setgid, if it cannot setuid, or if it cannot run .IR child . Otherwise its exit code is the same as that of .IR child . +.SH OPTIONS +.TP +.B \-s +Set account's supplementary gids. .SH SEE ALSO supervise(8), svc(8), diff --git a/setuidgid.c b/setuidgid.c index 8c683de..5fe963c 100644 --- a/setuidgid.c +++ b/setuidgid.c @@ -3,17 +3,32 @@ #include "prot.h" #include "strerr.h" #include "pathexec.h" +#include "sgetopt.h" #define FATAL "setuidgid: fatal: " +void usage() { + strerr_die1x(100,"setuidgid: usage: setuidgid [-s] account child"); +} + const char *account; struct passwd *pw; +int flag2ndgids = 0; int main(int argc,const char *const *argv,const char *const *envp) { - account = *++argv; - if (!account || !*++argv) - strerr_die1x(100,"setuidgid: usage: setuidgid account child"); + int opt; + + while ((opt = getopt(argc,argv,"s")) != opteof) + switch(opt) { + case 's': flag2ndgids = 1; break; + default: usage(); + } + + argv += optind; + if (!*argv) usage(); + account = *argv++; + if (!*argv) usage(); pw = getpwnam(account); if (!pw) @@ -21,6 +36,8 @@ int main(int argc,const char *const *argv,const char *const *envp) if (prot_gid(pw->pw_gid) == -1) strerr_die2sys(111,FATAL,"unable to setgid: "); + if (flag2ndgids && prot_gids(pw->pw_name, pw->pw_gid) == -1) + strerr_die2sys(111,FATAL,"unable to initgroups: "); if (prot_uid(pw->pw_uid) == -1) strerr_die2sys(111,FATAL,"unable to setuid: "); -- 1.7.1