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
8aa60255
Unverified
Commit
8aa60255
authored
Apr 01, 2021
by
Stéphane Graber
Committed by
GitHub
Apr 01, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3762 from brauner/2021-03-31/fixes
fixes: Makefile, lxc-user-nic, simplify get_network_config_ops()
parents
b405dec6
7707b0e0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
85 deletions
+74
-85
lxc_user_nic.c
src/lxc/cmd/lxc_user_nic.c
+21
-24
confile.c
src/lxc/confile.c
+0
-0
confile.h
src/lxc/confile.h
+8
-5
string_utils.c
src/lxc/string_utils.c
+6
-40
string_utils.h
src/lxc/string_utils.h
+4
-16
lxc_copy.c
src/lxc/tools/lxc_copy.c
+35
-0
No files found.
src/lxc/cmd/lxc_user_nic.c
View file @
8aa60255
...
...
@@ -233,10 +233,10 @@ struct alloted_s {
struct
alloted_s
*
next
;
};
static
struct
alloted_s
*
append_alloted
(
struct
alloted_s
**
head
,
char
*
name
,
int
n
)
static
struct
alloted_s
*
append_alloted
(
struct
alloted_s
**
head
,
char
*
name
,
int
n
)
{
struct
alloted_s
*
cur
,
*
al
;
__do_free
struct
alloted_s
*
al
=
NULL
;
struct
alloted_s
*
cur
;
if
(
!
head
||
!
name
)
{
/* Sanity check. Parameters should not be null. */
...
...
@@ -244,32 +244,29 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name,
return
NULL
;
}
al
=
m
alloc
(
sizeof
(
struct
alloted_s
));
al
=
z
alloc
(
sizeof
(
struct
alloted_s
));
if
(
!
al
)
{
CMD_SYSERROR
(
"Failed to allocate memory
\n
"
);
return
NULL
;
}
al
->
name
=
strdup
(
name
);
if
(
!
al
->
name
)
{
free
(
al
);
if
(
!
al
->
name
)
return
NULL
;
}
al
->
allowed
=
n
;
al
->
next
=
NULL
;
if
(
!*
head
)
{
if
(
*
head
)
{
cur
=
*
head
;
while
(
cur
->
next
)
cur
=
cur
->
next
;
cur
->
next
=
al
;
}
else
{
*
head
=
al
;
return
al
;
}
cur
=
*
head
;
while
(
cur
->
next
)
cur
=
cur
->
next
;
cur
->
next
=
al
;
return
al
;
return
move_ptr
(
al
);
}
static
void
free_alloted
(
struct
alloted_s
**
head
)
...
...
@@ -321,10 +318,10 @@ static int get_alloted(char *me, char *intype, char *link,
if
(
ret
!=
4
)
continue
;
if
(
strlen
(
name
)
==
0
)
if
(
is_empty_string
(
name
)
)
continue
;
if
(
strcmp
(
name
,
me
))
{
if
(
!
strequal
(
name
,
me
))
{
if
(
name
[
0
]
!=
'@'
)
continue
;
...
...
@@ -332,17 +329,17 @@ static int get_alloted(char *me, char *intype, char *link,
continue
;
}
if
(
strcmp
(
type
,
intype
))
if
(
!
strequal
(
type
,
intype
))
continue
;
if
(
strcmp
(
link
,
br
))
if
(
!
strequal
(
link
,
br
))
continue
;
/*
Found the user or group with the appropriate settings,
*
therefore finish the search. What to do if there are more
* th
an one applicable lines? not specified in the docs. Sinc
e
*
getline is implemented with realloc, we don't need to free
*
line until exiting func
.
/*
*
Found the user or group with the appropriate settings,
* th
erefore finish the search. What to do if there are is mor
e
*
than one applicable line? Currently this is not specified in
*
the docs
.
*
* If append_alloted returns NULL, e.g. due to a malloc error,
* we set count to 0 and break the loop, allowing cleanup and
...
...
src/lxc/confile.c
View file @
8aa60255
This diff is collapsed.
Click to expand it.
src/lxc/confile.h
View file @
8aa60255
...
...
@@ -32,12 +32,15 @@ typedef int (*config_get_cb)(const char *key, char *value, int inlen,
typedef
int
(
*
config_clr_cb
)(
const
char
*
key
,
struct
lxc_conf
*
conf
,
void
*
data
);
#define LXC_CONFIG_MEMBERS \
char *name; \
bool strict; \
config_set_cb set; \
config_get_cb get; \
config_clr_cb clr
struct
lxc_config_t
{
char
*
name
;
bool
strict
;
config_set_cb
set
;
config_get_cb
get
;
config_clr_cb
clr
;
LXC_CONFIG_MEMBERS
;
};
struct
new_config_item
{
...
...
src/lxc/string_utils.c
View file @
8aa60255
...
...
@@ -192,41 +192,6 @@ char *lxc_string_join(const char *sep, const char **parts, bool use_as_prefix)
return
result
;
}
char
**
lxc_normalize_path
(
const
char
*
path
)
{
char
**
components
;
size_t
components_len
=
0
;
size_t
pos
=
0
;
components
=
lxc_string_split
(
path
,
'/'
);
if
(
!
components
)
return
NULL
;
/* resolve '.' and '..' */
for
(
pos
=
0
;
pos
<
components_len
;)
{
if
(
strequal
(
components
[
pos
],
"."
)
||
(
strequal
(
components
[
pos
],
".."
)
&&
pos
==
0
))
{
/* eat this element */
free
(
components
[
pos
]);
memmove
(
&
components
[
pos
],
&
components
[
pos
+
1
],
sizeof
(
char
*
)
*
(
components_len
-
pos
));
components_len
--
;
}
else
if
(
strequal
(
components
[
pos
],
".."
))
{
/* eat this and the previous element */
free
(
components
[
pos
-
1
]);
free
(
components
[
pos
]);
memmove
(
&
components
[
pos
-
1
],
&
components
[
pos
+
1
],
sizeof
(
char
*
)
*
(
components_len
-
pos
));
components_len
-=
2
;
pos
--
;
}
else
{
pos
++
;
}
}
return
components
;
}
/* taken from systemd */
char
*
path_simplify
(
const
char
*
path
)
{
...
...
@@ -672,8 +637,9 @@ int lxc_safe_uint64(const char *numstr, uint64_t *converted, int base)
return
0
;
}
int
lxc_safe_int64_residual
(
const
char
*
numstr
,
int64_t
*
converted
,
int
base
,
char
*
residual
,
size_t
residual_len
)
int
lxc_safe_int64_residual
(
const
char
*
restrict
numstr
,
int64_t
*
restrict
converted
,
int
base
,
char
*
restrict
residual
,
size_t
residual_len
)
{
char
*
remaining
=
NULL
;
int64_t
u
;
...
...
@@ -692,7 +658,7 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch
errno
=
0
;
u
=
strtoll
(
numstr
,
&
remaining
,
base
);
if
(
errno
==
ERANGE
&&
u
==
INT64_MAX
)
return
-
ERANGE
;
return
ret_errno
(
ERANGE
)
;
if
(
remaining
==
numstr
)
return
-
EINVAL
;
...
...
@@ -705,11 +671,11 @@ int lxc_safe_int64_residual(const char *numstr, int64_t *converted, int base, ch
len
=
strlen
(
remaining
);
if
(
len
>=
residual_len
)
return
-
EINVAL
;
return
ret_errno
(
EINVAL
)
;
memcpy
(
residual
,
remaining
,
len
);
}
else
if
(
*
remaining
!=
'\0'
)
{
return
-
EINVAL
;
return
ret_errno
(
EINVAL
)
;
}
out:
...
...
src/lxc/string_utils.h
View file @
8aa60255
...
...
@@ -30,21 +30,7 @@ __hidden extern char *lxc_string_replace(const char *needle, const char *replace
const
char
*
haystack
);
__hidden
extern
bool
lxc_string_in_array
(
const
char
*
needle
,
const
char
**
haystack
);
__hidden
extern
char
*
lxc_string_join
(
const
char
*
sep
,
const
char
**
parts
,
bool
use_as_prefix
);
/*
* Normalize and split path: Leading and trailing / are removed, multiple
* / are compactified, .. and . are resolved (.. on the top level is considered
* identical to .).
* Examples:
* / -> { NULL }
* foo/../bar -> { bar, NULL }
* ../../ -> { NULL }
* ./bar/baz/.. -> { bar, NULL }
* foo//bar -> { foo, bar, NULL }
*/
__hidden
extern
char
**
lxc_normalize_path
(
const
char
*
path
);
/* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
__hidden
extern
char
*
lxc_deslashify
(
const
char
*
path
);
__hidden
extern
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
);
/*
...
...
@@ -78,8 +64,10 @@ __hidden extern int lxc_safe_long(const char *numstr, long int *converted);
__hidden
extern
int
lxc_safe_long_long
(
const
char
*
numstr
,
long
long
int
*
converted
);
__hidden
extern
int
lxc_safe_ulong
(
const
char
*
numstr
,
unsigned
long
*
converted
);
__hidden
extern
int
lxc_safe_uint64
(
const
char
*
numstr
,
uint64_t
*
converted
,
int
base
);
__hidden
extern
int
lxc_safe_int64_residual
(
const
char
*
numstr
,
int64_t
*
converted
,
int
base
,
char
*
residual
,
size_t
residual_len
);
__hidden
extern
int
lxc_safe_int64_residual
(
const
char
*
restrict
numstr
,
int64_t
*
restrict
converted
,
int
base
,
char
*
restrict
residual
,
size_t
residual_len
);
/* Handles B, kb, MB, GB. Detects overflows and reports -ERANGE. */
__hidden
extern
int
parse_byte_size_string
(
const
char
*
s
,
long
long
int
*
converted
);
...
...
src/lxc/tools/lxc_copy.c
View file @
8aa60255
...
...
@@ -289,6 +289,41 @@ static int mk_rand_ovl_dirs(struct mnts *mnts, unsigned int num, struct lxc_argu
return
0
;
}
static
char
**
lxc_normalize_path
(
const
char
*
path
)
{
char
**
components
;
size_t
components_len
=
0
;
size_t
pos
=
0
;
components
=
lxc_string_split
(
path
,
'/'
);
if
(
!
components
)
return
NULL
;
/* resolve '.' and '..' */
for
(
pos
=
0
;
pos
<
components_len
;)
{
if
(
strequal
(
components
[
pos
],
"."
)
||
(
strequal
(
components
[
pos
],
".."
)
&&
pos
==
0
))
{
/* eat this element */
free
(
components
[
pos
]);
memmove
(
&
components
[
pos
],
&
components
[
pos
+
1
],
sizeof
(
char
*
)
*
(
components_len
-
pos
));
components_len
--
;
}
else
if
(
strequal
(
components
[
pos
],
".."
))
{
/* eat this and the previous element */
free
(
components
[
pos
-
1
]);
free
(
components
[
pos
]);
memmove
(
&
components
[
pos
-
1
],
&
components
[
pos
+
1
],
sizeof
(
char
*
)
*
(
components_len
-
pos
));
components_len
-=
2
;
pos
--
;
}
else
{
pos
++
;
}
}
return
components
;
}
static
char
*
construct_path
(
char
*
path
,
bool
as_prefix
)
{
char
**
components
=
NULL
;
...
...
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