aboutsummaryrefslogtreecommitdiff
path: root/libpwdgrp/uidgid_get.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-26 22:47:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-26 22:47:42 +0000
commitcce38586aee7fe892ca1c837ee08a96bd3454ee9 (patch)
tree2cce1db0f921fdc3e899641dd9c59f459ce4b07d /libpwdgrp/uidgid_get.c
parentf8ea0f3a66559a00c41fd7877bdc241973a60f8c (diff)
downloadbusybox-w32-cce38586aee7fe892ca1c837ee08a96bd3454ee9.tar.gz
busybox-w32-cce38586aee7fe892ca1c837ee08a96bd3454ee9.tar.bz2
busybox-w32-cce38586aee7fe892ca1c837ee08a96bd3454ee9.zip
start_stop_daemon: add -chuid support
Diffstat (limited to 'libpwdgrp/uidgid_get.c')
-rw-r--r--libpwdgrp/uidgid_get.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c
index 69c228e16..f10b40654 100644
--- a/libpwdgrp/uidgid_get.c
+++ b/libpwdgrp/uidgid_get.c
@@ -27,6 +27,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28#include "busybox.h" 28#include "busybox.h"
29 29
30/* Always sets uid and gid */
30int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) 31int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
31{ 32{
32 struct passwd *pwd; 33 struct passwd *pwd;
@@ -53,6 +54,7 @@ int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
53 goto skip; 54 goto skip;
54 } 55 }
55 } 56 }
57 /* Either it is not numeric, or caller disallows numeric username */
56 pwd = getpwnam(user); 58 pwd = getpwnam(user);
57 if (!pwd) 59 if (!pwd)
58 return 0; 60 return 0;
@@ -75,6 +77,40 @@ int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
75 return 1; 77 return 1;
76} 78}
77 79
80/* chown-like:
81 * "user" sets uid only,
82 * ":group" sets gid only
83 * "user:" sets uid and gid (to user's primary group id)
84 * "user:group" sets uid and gid
85 * ('unset' uid or gid is actually set to -1)
86 */
87void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group)
88{
89 char *group;
90
91 u->uid = -1;
92 u->gid = -1;
93
94 /* Check if there is a group name */
95 group = strchr(user_group, '.'); /* deprecated? */
96 if (!group)
97 group = strchr(user_group, ':');
98 else
99 *group = ':'; /* replace '.' with ':' */
100
101 /* Parse "user[:[group]]" */
102 if (!group) { /* "user" */
103 u->uid = get_ug_id(user_group, xuname2uid);
104 } else if (group == user_group) { /* ":group" */
105 u->gid = get_ug_id(group + 1, xgroup2gid);
106 } else {
107 if (!group[1]) /* "user:" */
108 *group = '\0';
109 if (!get_uidgid(u, user_group, 1))
110 bb_error_msg_and_die("unknown user/group %s", user_group);
111 }
112}
113
78#if 0 114#if 0
79#include <stdio.h> 115#include <stdio.h>
80int main() 116int main()