Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
5207b430
Unverified
Commit
5207b430
authored
Dec 09, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
confile_utils: cleanup parse_idmaps()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
29bde371
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
35 deletions
+26
-35
confile_utils.c
src/lxc/confile_utils.c
+26
-35
No files found.
src/lxc/confile_utils.c
View file @
5207b430
...
...
@@ -18,6 +18,7 @@
#include "log.h"
#include "lxccontainer.h"
#include "macro.h"
#include "memory_utils.h"
#include "network.h"
#include "parse.h"
#include "utils.h"
...
...
@@ -31,16 +32,16 @@ lxc_log_define(confile_utils, lxc);
int
parse_idmaps
(
const
char
*
idmap
,
char
*
type
,
unsigned
long
*
nsid
,
unsigned
long
*
hostid
,
unsigned
long
*
range
)
{
__do_free
char
*
dup
=
NULL
;
int
ret
=
-
1
;
unsigned
long
tmp_hostid
,
tmp_nsid
,
tmp_range
;
char
tmp_type
;
char
*
window
,
*
slide
;
char
*
dup
=
NULL
;
/* Duplicate string. */
dup
=
strdup
(
idmap
);
if
(
!
dup
)
goto
on_error
;
return
ret_errno
(
ENOMEM
)
;
/* A prototypical idmap entry would be: "u 1000 1000000 65536" */
...
...
@@ -49,13 +50,11 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
/* skip whitespace */
slide
+=
strspn
(
slide
,
"
\t\r
"
);
if
(
slide
!=
window
&&
*
slide
==
'\0'
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Validate type. */
if
(
*
slide
!=
'u'
&&
*
slide
!=
'g'
)
{
ERROR
(
"Invalid id mapping type: %c"
,
*
slide
);
goto
on_error
;
}
if
(
*
slide
!=
'u'
&&
*
slide
!=
'g'
)
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Invalid id mapping type: %c"
,
*
slide
);
/* Assign type. */
tmp_type
=
*
slide
;
...
...
@@ -68,7 +67,7 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
slide
+=
strspn
(
slide
,
"
\t\r
"
);
/* There must be whitespace. */
if
(
slide
==
window
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Mark beginning of nsid. */
window
=
slide
;
...
...
@@ -76,15 +75,14 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
slide
+=
strcspn
(
slide
,
"
\t\r
"
);
/* There must be non-whitespace. */
if
(
slide
==
window
||
*
slide
==
'\0'
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Mark end of nsid. */
*
slide
=
'\0'
;
/* Parse nsid. */
if
(
lxc_safe_ulong
(
window
,
&
tmp_nsid
)
<
0
)
{
ERROR
(
"Failed to parse nsid: %s"
,
window
);
goto
on_error
;
}
ret
=
lxc_safe_ulong
(
window
,
&
tmp_nsid
);
if
(
ret
<
0
)
return
log_error_errno
(
ret
,
errno
,
"Failed to parse nsid: %s"
,
window
);
/* Move beyond \0. */
slide
++
;
...
...
@@ -94,7 +92,7 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
* So only ensure that we're not at the end of the string.
*/
if
(
*
slide
==
'\0'
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Mark beginning of hostid. */
window
=
slide
;
...
...
@@ -102,15 +100,14 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
slide
+=
strcspn
(
slide
,
"
\t\r
"
);
/* There must be non-whitespace. */
if
(
slide
==
window
||
*
slide
==
'\0'
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Mark end of nsid. */
*
slide
=
'\0'
;
/* Parse hostid. */
if
(
lxc_safe_ulong
(
window
,
&
tmp_hostid
)
<
0
)
{
ERROR
(
"Failed to parse hostid: %s"
,
window
);
goto
on_error
;
}
ret
=
lxc_safe_ulong
(
window
,
&
tmp_hostid
);
if
(
ret
<
0
)
return
log_error_errno
(
ret
,
errno
,
"Failed to parse hostid: %s"
,
window
);
/* Move beyond \0. */
slide
++
;
...
...
@@ -120,7 +117,7 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
* So only ensure that we're not at the end of the string.
*/
if
(
*
slide
==
'\0'
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Mark beginning of range. */
window
=
slide
;
...
...
@@ -128,35 +125,29 @@ int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
slide
+=
strcspn
(
slide
,
"
\t\r
"
);
/* There must be non-whitespace. */
if
(
slide
==
window
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* The range is the last valid entry we expect. So make sure that there
* is no trailing garbage and if there is, error out.
*/
if
(
*
(
slide
+
strspn
(
slide
,
"
\t\r\n
"
))
!=
'\0'
)
goto
on_error
;
return
ret_errno
(
EINVAL
)
;
/* Mark end of range. */
*
slide
=
'\0'
;
/* Parse range. */
if
(
lxc_safe_ulong
(
window
,
&
tmp_range
)
<
0
)
{
ERROR
(
"Failed to parse id mapping range: %s"
,
window
);
goto
on_error
;
}
ret
=
lxc_safe_ulong
(
window
,
&
tmp_range
);
if
(
ret
<
0
)
return
log_error_errno
(
ret
,
errno
,
"Failed to parse id mapping range: %s"
,
window
);
*
type
=
tmp_type
;
*
nsid
=
tmp_nsid
;
*
type
=
tmp_type
;
*
nsid
=
tmp_nsid
;
*
hostid
=
tmp_hostid
;
*
range
=
tmp_range
;
*
range
=
tmp_range
;
/* Yay, we survived. */
ret
=
0
;
on_error:
free
(
dup
);
return
ret
;
return
0
;
}
bool
lxc_config_value_empty
(
const
char
*
value
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment