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
21002b39
Commit
21002b39
authored
Jun 09, 2015
by
Henrik Kjölhede
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed memory checks and faulty loop in get_alloted according to comments
Signed-off-by:
Henrik Kjölhede
<
hkjolhede@gmail.com
>
parent
1940bff4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
28 deletions
+43
-28
lxc-usernet.sgml.in
doc/lxc-usernet.sgml.in
+6
-6
lxc_user_nic.c
src/lxc/lxc_user_nic.c
+37
-22
No files found.
doc/lxc-usernet.sgml.in
View file @
21002b39
...
@@ -133,12 +133,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
...
@@ -133,12 +133,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</variablelist>
</variablelist>
<para>
<para>
Since a user can be be specified both by username as well as one or
Since a user can be be specified both by username as well as one or
more usergroups, it is possible that several configuration lines
more usergroups, it is possible that several configuration lines
enable that user to create network interfaces. In such cases, any
enable that user to create network interfaces. In such cases, any
interfaces create are counted towards the quotas of the user or group
interfaces create are counted towards the quotas of the user or group
in the order in which they appear in the file. If the quota of one
in the order in which they appear in the file. If the quota of one
line is full, the rest will be parsed until one is found or the end of
line is full, the rest will be parsed until one is found or the end of
the file.
the file.
</para>
</para>
</refsect2>
</refsect2>
...
...
src/lxc/lxc_user_nic.c
View file @
21002b39
...
@@ -97,42 +97,63 @@ static char *get_username(void)
...
@@ -97,42 +97,63 @@ static char *get_username(void)
return
pwd
->
pw_name
;
return
pwd
->
pw_name
;
}
}
static
void
free_groupnames
(
char
**
groupnames
)
{
char
**
group
;
for
(
group
=
groupnames
;
group
!=
NULL
;
group
++
)
free
(
*
group
);
free
(
groupnames
);
}
static
char
**
get_groupnames
(
void
)
static
char
**
get_groupnames
(
void
)
{
{
int
ngroups
;
int
ngroups
;
gid_t
*
group_ids
;
gid_t
*
group_ids
;
int
ret
,
i
,
j
;
int
ret
,
i
;
char
**
groupnames
;
char
**
groupnames
;
struct
group
*
gr
;
struct
group
*
gr
;
ngroups
=
getgroups
(
0
,
NULL
);
ngroups
=
getgroups
(
0
,
NULL
);
if
(
ngroups
==
-
1
)
{
if
(
ngroups
==
-
1
)
{
fprintf
(
stderr
,
"Failed to get number of groups user belongs to
\n
"
);
fprintf
(
stderr
,
"Failed to get number of groups user belongs to
: %s
\n
"
,
strerror
(
errno
)
);
return
NULL
;
return
NULL
;
}
}
if
(
ngroups
==
0
)
return
NULL
;
group_ids
=
(
gid_t
*
)
malloc
(
sizeof
(
gid_t
)
*
ngroups
);
group_ids
=
(
gid_t
*
)
malloc
(
sizeof
(
gid_t
)
*
ngroups
);
if
(
group_ids
==
NULL
)
{
fprintf
(
stderr
,
"Out of memory while getting groups the user belongs to
\n
"
);
return
NULL
;
}
ret
=
getgroups
(
ngroups
,
group_ids
);
ret
=
getgroups
(
ngroups
,
group_ids
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
free
(
group_ids
);
free
(
group_ids
);
fprintf
(
stderr
,
"Failed to get process groups
\n
"
);
fprintf
(
stderr
,
"Failed to get process groups
: %s
\n
"
,
strerror
(
errno
)
);
return
NULL
;
return
NULL
;
}
}
groupnames
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
(
ngroups
+
1
));
groupnames
=
(
char
**
)
malloc
(
sizeof
(
char
*
)
*
(
ngroups
+
1
));
if
(
groupnames
==
NULL
)
{
free
(
group_ids
);
fprintf
(
stderr
,
"Out of memory while getting group names
\n
"
);
return
NULL
;
}
memset
(
groupnames
,
0
,
sizeof
(
char
*
)
*
(
ngroups
+
1
));
for
(
i
=
0
;
i
<
ngroups
;
i
++
)
{
for
(
i
=
0
;
i
<
ngroups
;
i
++
)
{
gr
=
getgrgid
(
group_ids
[
i
]);
gr
=
getgrgid
(
group_ids
[
i
]);
if
(
gr
==
NULL
)
{
if
(
gr
==
NULL
)
{
fprintf
(
stderr
,
"Failed to get group name
\n
"
);
fprintf
(
stderr
,
"Failed to get group name
\n
"
);
free
(
group_ids
);
free
(
group_ids
);
for
(
j
=
0
;
j
<
i
;
j
++
)
{
free_groupnames
(
groupnames
);
free
(
groupnames
[
j
]);
}
free
(
groupnames
);
return
NULL
;
return
NULL
;
}
}
...
@@ -141,29 +162,16 @@ static char **get_groupnames(void)
...
@@ -141,29 +162,16 @@ static char **get_groupnames(void)
if
(
groupnames
[
i
]
==
NULL
)
{
if
(
groupnames
[
i
]
==
NULL
)
{
fprintf
(
stderr
,
"Failed to copy group name: %s"
,
gr
->
gr_name
);
fprintf
(
stderr
,
"Failed to copy group name: %s"
,
gr
->
gr_name
);
free
(
group_ids
);
free
(
group_ids
);
for
(
j
=
0
;
j
<
i
;
j
++
)
{
free_groupnames
(
groupnames
);
free
(
groupnames
[
j
]);
}
free
(
groupnames
);
return
NULL
;
return
NULL
;
}
}
}
}
groupnames
[
ngroups
]
=
NULL
;
free
(
group_ids
);
free
(
group_ids
);
return
groupnames
;
return
groupnames
;
}
}
static
void
free_groupnames
(
char
**
groupnames
)
{
char
**
group
;
for
(
group
=
groupnames
;
group
!=
NULL
;
group
++
)
free
(
*
group
);
free
(
groupnames
);
}
static
bool
name_is_in_groupnames
(
char
*
name
,
char
**
groupnames
)
static
bool
name_is_in_groupnames
(
char
*
name
,
char
**
groupnames
)
{
{
while
(
groupnames
!=
NULL
)
{
while
(
groupnames
!=
NULL
)
{
...
@@ -197,6 +205,12 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int
...
@@ -197,6 +205,12 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int
}
}
al
->
name
=
strdup
(
name
);
al
->
name
=
strdup
(
name
);
if
(
al
->
name
==
NULL
)
{
free
(
al
);
return
NULL
;
}
al
->
allowed
=
n
;
al
->
allowed
=
n
;
al
->
next
=
NULL
;
al
->
next
=
NULL
;
...
@@ -283,12 +297,13 @@ static int get_alloted(char *me, char *intype, char *link, struct alloted_s **al
...
@@ -283,12 +297,13 @@ static int get_alloted(char *me, char *intype, char *link, struct alloted_s **al
*/
*/
append_alloted
(
alloted
,
name
,
n
);
append_alloted
(
alloted
,
name
,
n
);
count
+=
n
;
count
+=
n
;
break
;
}
}
free_groupnames
(
groups
);
free_groupnames
(
groups
);
fclose
(
fin
);
fclose
(
fin
);
free
(
line
);
free
(
line
);
// now return the total number of nics that this user can create
return
count
;
return
count
;
}
}
...
...
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