]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/confile_utils.c
3 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2017 Canonical Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 int parse_idmaps(const char *idmap
, char *type
, unsigned long *nsid
,
26 unsigned long *hostid
, unsigned long *range
)
29 unsigned long tmp_hostid
, tmp_nsid
, tmp_range
;
34 /* Duplicate string. */
39 /* A prototypical idmap entry would be: "u 1000 1000000 65536" */
44 slide
+= strspn(slide
, " \t\r");
45 if (slide
!= window
&& *slide
== '\0')
49 if (*slide
!= 'u' && *slide
!= 'g')
54 /* move beyond type */
58 /* Validate that only whitespace follows. */
59 slide
+= strspn(slide
, " \t\r");
60 /* There must be whitespace. */
64 /* Mark beginning of nsuid. */
66 /* Validate that non-whitespace follows. */
67 slide
+= strcspn(slide
, " \t\r");
68 /* There must be non-whitespace. */
69 if (slide
== window
|| *slide
== '\0')
71 /* Mark end of nsuid. */
75 if (lxc_safe_ulong(window
, &tmp_nsid
) < 0)
82 /* Validate that only whitespace follows. */
83 slide
+= strspn(slide
, " \t\r");
84 /* If there was only one whitespace then we whiped it with our \0 above.
85 * So only ensure that we're not at the end of the string.
90 /* Mark beginning of hostid. */
92 /* Validate that non-whitespace follows. */
93 slide
+= strcspn(slide
, " \t\r");
94 /* There must be non-whitespace. */
95 if (slide
== window
|| *slide
== '\0')
97 /* Mark end of nsuid. */
101 if (lxc_safe_ulong(window
, &tmp_hostid
) < 0)
104 /* Move beyond \0. */
108 /* Validate that only whitespace follows. */
109 slide
+= strspn(slide
, " \t\r");
110 /* If there was only one whitespace then we whiped it with our \0 above.
111 * So only ensure that we're not at the end of the string.
116 /* Mark beginning of range. */
118 /* Validate that non-whitespace follows. */
119 slide
+= strcspn(slide
, " \t\r");
120 /* There must be non-whitespace. */
124 /* The range is the last valid entry we expect. So make sure that there
125 * is not trailing garbage and if there is, error out.
127 if (*(slide
+ strspn(slide
, " \t\r\n")) != '\0')
129 /* Mark end of range. */
133 if (lxc_safe_ulong(window
, &tmp_range
) < 0)
138 *hostid
= tmp_hostid
;
141 /* Yay, we survived. */