1
From ebiederm@xmission.com Tue Jan 22 09:17:02 2013
2
Return-Path: <ebiederm@xmission.com>
3
X-Original-To: serge@hallyn.com
4
Delivered-To: serge@hallyn.com
5
Received: by mail.hallyn.com (Postfix, from userid 5001)
6
id 480ABC80F4; Tue, 22 Jan 2013 09:17:02 +0000 (UTC)
7
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail
9
X-Spam-Status: No, score=0.1 required=8.0 tests=BAD_ENC_HEADER,BAYES_00
10
autolearn=no version=3.3.1
11
Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232])
12
(using TLSv1 with cipher AES256-SHA (256/256 bits))
13
(No client certificate requested)
14
by mail.hallyn.com (Postfix) with ESMTPS id 90ACFC80D1
15
for <serge@hallyn.com>; Tue, 22 Jan 2013 09:16:57 +0000 (UTC)
16
Received: from out01.mta.xmission.com ([166.70.13.231])
17
by out02.mta.xmission.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
19
(envelope-from <ebiederm@xmission.com>)
20
id 1TxZwp-0007cg-9X; Tue, 22 Jan 2013 02:15:15 -0700
21
Received: from in02.mta.xmission.com ([166.70.13.52])
22
by out01.mta.xmission.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
24
(envelope-from <ebiederm@xmission.com>)
25
id 1TxZwo-0006DN-OT; Tue, 22 Jan 2013 02:15:14 -0700
26
Received: from c-98-207-153-68.hsd1.ca.comcast.net ([98.207.153.68] helo=eric-ThinkPad-X220.xmission.com)
27
by in02.mta.xmission.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16)
29
(envelope-from <ebiederm@xmission.com>)
30
id 1TxZwj-0004g0-9e; Tue, 22 Jan 2013 02:15:14 -0700
31
From: ebiederm@xmission.com (Eric W. Biederman)
32
To: Nicolas =?utf-8?Q?Fran=C3=A7ois?= <nicolas.francois@centraliens.net>
33
Cc: <Pkg-shadow-devel@lists.alioth.debian.org>, Linux Containers <containers@lists.linux-foundation.org>, "Michael Kerrisk \(man-pages\)" <mtk.manpages@gmail.com>, "Serge E. Hallyn" <serge@hallyn.com>
34
References: <87d2wxshu0.fsf@xmission.com>
35
Date: Tue, 22 Jan 2013 01:15:05 -0800
36
In-Reply-To: <87d2wxshu0.fsf@xmission.com> (Eric W. Biederman's message of
37
"Tue, 22 Jan 2013 01:11:19 -0800")
38
Message-ID: <87fw1tr33a.fsf@xmission.com>
39
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)
41
Content-Type: text/plain
42
X-XM-AID: U2FsdGVkX19KHX5xUOkaLY5iIEqDVLxZKDTByyA0Xk8=
43
X-SA-Exim-Connect-IP: 98.207.153.68
44
X-SA-Exim-Mail-From: ebiederm@xmission.com
45
Subject: [PATCH 05/11] Implement find_new_sub_uids find_new_sub_gids
46
X-SA-Exim-Version: 4.2.1 (built Wed, 14 Nov 2012 14:26:46 -0700)
47
X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com)
54
Functions for finding new subordinate uid and gids ranges for use
57
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
59
lib/prototypes.h | 9 ++++
60
libmisc/Makefile.am | 2 +
61
libmisc/find_new_sub_gids.c | 87 +++++++++++++++++++++++++++++++++++++++++++
62
libmisc/find_new_sub_uids.c | 87 +++++++++++++++++++++++++++++++++++++++++++
63
4 files changed, 185 insertions(+), 0 deletions(-)
64
create mode 100644 libmisc/find_new_sub_gids.c
65
create mode 100644 libmisc/find_new_sub_uids.c
67
Index: shadow/lib/prototypes.h
68
===================================================================
69
--- shadow.orig/lib/prototypes.h 2013-02-01 15:27:52.044080373 -0600
70
+++ shadow/lib/prototypes.h 2013-02-01 15:27:52.040080373 -0600
73
/*@null@*/uid_t const *preferred_uid);
75
+/* find_new_sub_gids.c */
76
+extern int find_new_sub_gids (const char *owner,
77
+ gid_t *range_start, unsigned long *range_count);
79
+/* find_new_sub_uids.c */
80
+extern int find_new_sub_uids (const char *owner,
81
+ uid_t *range_start, unsigned long *range_count);
85
extern int get_gid (const char *gidstr, gid_t *gid);
87
Index: shadow/libmisc/Makefile.am
88
===================================================================
89
--- shadow.orig/libmisc/Makefile.am 2013-02-01 15:27:52.044080373 -0600
90
+++ shadow/libmisc/Makefile.am 2013-02-01 15:27:52.040080373 -0600
95
+ find_new_sub_gids.c \
96
+ find_new_sub_uids.c \
100
Index: shadow/libmisc/find_new_sub_gids.c
101
===================================================================
102
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
103
+++ shadow/libmisc/find_new_sub_gids.c 2013-02-01 15:27:52.040080373 -0600
106
+ * Copyright (c) 2012 Eric Biederman
108
+ * Redistribution and use in source and binary forms, with or without
109
+ * modification, are permitted provided that the following conditions
111
+ * 1. Redistributions of source code must retain the above copyright
112
+ * notice, this list of conditions and the following disclaimer.
113
+ * 2. Redistributions in binary form must reproduce the above copyright
114
+ * notice, this list of conditions and the following disclaimer in the
115
+ * documentation and/or other materials provided with the distribution.
116
+ * 3. The name of the copyright holders or contributors may not be used to
117
+ * endorse or promote products derived from this software without
118
+ * specific prior written permission.
120
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
121
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
122
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
123
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
124
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
125
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
126
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
127
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
128
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
129
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
130
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139
+#include "prototypes.h"
140
+#include "subordinateio.h"
144
+ * find_new_sub_gids - Find a new unused range of GIDs.
146
+ * If successful, find_new_sub_gids provides a range of unused
147
+ * user IDs in the [SUB_GID_MIN:SUB_GID_MAX] range.
149
+ * Return 0 on success, -1 if no unused GIDs are available.
151
+int find_new_sub_gids (const char *owner,
152
+ gid_t *range_start, unsigned long *range_count)
154
+ unsigned long min, max;
155
+ unsigned long count;
158
+ assert (range_start != NULL);
159
+ assert (range_count != NULL);
161
+ min = getdef_ulong ("SUB_GID_MIN", 100000UL);
162
+ max = getdef_ulong ("SUB_GID_MAX", 600100000UL);
163
+ count = getdef_ulong ("SUB_GID_COUNT", 10000);
165
+ /* Is there a preferred range that works? */
166
+ if ((*range_count != 0) &&
167
+ (*range_start >= min) &&
168
+ (((*range_start) + (*range_count) - 1) <= max) &&
169
+ is_sub_gid_range_free(*range_start, *range_count)) {
173
+ if (max < (min + count)) {
174
+ (void) fprintf (stderr,
175
+ _("%s: Invalid configuration: SUB_GID_MIN (%lu), SUB_GID_MAX (%lu)\n"),
179
+ start = sub_gid_find_free_range(min, max, count);
180
+ if (start == (gid_t)-1) {
182
+ _("%s: Can't get unique secondary GID range\n"),
184
+ SYSLOG ((LOG_WARN, "no more available secondary GIDs on the system"));
187
+ *range_start = start;
188
+ *range_count = count;
192
Index: shadow/libmisc/find_new_sub_uids.c
193
===================================================================
194
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
195
+++ shadow/libmisc/find_new_sub_uids.c 2013-02-01 15:27:52.040080373 -0600
198
+ * Copyright (c) 2012 Eric Biederman
200
+ * Redistribution and use in source and binary forms, with or without
201
+ * modification, are permitted provided that the following conditions
203
+ * 1. Redistributions of source code must retain the above copyright
204
+ * notice, this list of conditions and the following disclaimer.
205
+ * 2. Redistributions in binary form must reproduce the above copyright
206
+ * notice, this list of conditions and the following disclaimer in the
207
+ * documentation and/or other materials provided with the distribution.
208
+ * 3. The name of the copyright holders or contributors may not be used to
209
+ * endorse or promote products derived from this software without
210
+ * specific prior written permission.
212
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
213
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
214
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
215
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
218
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
219
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
220
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
221
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
222
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
231
+#include "prototypes.h"
232
+#include "subordinateio.h"
236
+ * find_new_sub_uids - Find a new unused range of UIDs.
238
+ * If successful, find_new_sub_uids provides a range of unused
239
+ * user IDs in the [SUB_UID_MIN:SUB_UID_MAX] range.
241
+ * Return 0 on success, -1 if no unused UIDs are available.
243
+int find_new_sub_uids (const char *owner,
244
+ uid_t *range_start, unsigned long *range_count)
246
+ unsigned long min, max;
247
+ unsigned long count;
250
+ assert (range_start != NULL);
251
+ assert (range_count != NULL);
253
+ min = getdef_ulong ("SUB_UID_MIN", 100000UL);
254
+ max = getdef_ulong ("SUB_UID_MAX", 600100000UL);
255
+ count = getdef_ulong ("SUB_UID_COUNT", 10000);
257
+ /* Is there a preferred range that works? */
258
+ if ((*range_count != 0) &&
259
+ (*range_start >= min) &&
260
+ (((*range_start) + (*range_count) - 1) <= max) &&
261
+ is_sub_uid_range_free(*range_start, *range_count)) {
265
+ if (max < (min + count)) {
266
+ (void) fprintf (stderr,
267
+ _("%s: Invalid configuration: SUB_UID_MIN (%lu), SUB_UID_MAX (%lu)\n"),
271
+ start = sub_uid_find_free_range(min, max, count);
272
+ if (start == (uid_t)-1) {
274
+ _("%s: Can't get unique secondary UID range\n"),
276
+ SYSLOG ((LOG_WARN, "no more available secondary UIDs on the system"));
279
+ *range_start = start;
280
+ *range_count = count;