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
cd64caf5
Unverified
Commit
cd64caf5
authored
Aug 25, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Aug 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
af_unix: non-functional changes
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
a19b826d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
19 deletions
+25
-19
af_unix.c
src/lxc/af_unix.c
+24
-18
af_unix.h
src/lxc/af_unix.h
+1
-1
No files found.
src/lxc/af_unix.c
View file @
cd64caf5
...
...
@@ -38,7 +38,7 @@ lxc_log_define(lxc_af_unix, lxc);
int
lxc_abstract_unix_open
(
const
char
*
path
,
int
type
,
int
flags
)
{
int
fd
;
int
fd
,
ret
;
size_t
len
;
struct
sockaddr_un
addr
;
...
...
@@ -64,18 +64,24 @@ int lxc_abstract_unix_open(const char *path, int type, int flags)
/* addr.sun_path[0] has already been set to 0 by memset() */
strncpy
(
&
addr
.
sun_path
[
1
],
&
path
[
1
],
strlen
(
&
path
[
1
]));
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
))
{
ret
=
bind
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
if
(
ret
<
0
)
{
int
tmp
=
errno
;
close
(
fd
);
errno
=
tmp
;
return
-
1
;
}
if
(
type
==
SOCK_STREAM
&&
listen
(
fd
,
100
))
{
int
tmp
=
errno
;
close
(
fd
);
errno
=
tmp
;
return
-
1
;
if
(
type
==
SOCK_STREAM
)
{
ret
=
listen
(
fd
,
100
);
if
(
ret
<
0
)
{
int
tmp
=
errno
;
close
(
fd
);
errno
=
tmp
;
return
-
1
;
}
}
return
fd
;
...
...
@@ -84,13 +90,12 @@ int lxc_abstract_unix_open(const char *path, int type, int flags)
int
lxc_abstract_unix_close
(
int
fd
)
{
close
(
fd
);
return
0
;
}
int
lxc_abstract_unix_connect
(
const
char
*
path
)
{
int
fd
;
int
fd
,
ret
;
size_t
len
;
struct
sockaddr_un
addr
;
...
...
@@ -112,7 +117,9 @@ int lxc_abstract_unix_connect(const char *path)
/* addr.sun_path[0] has already been set to 0 by memset() */
strncpy
(
&
addr
.
sun_path
[
1
],
&
path
[
1
],
strlen
(
&
path
[
1
]));
if
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
))
{
ret
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
if
(
ret
<
0
)
{
close
(
fd
);
return
-
1
;
}
...
...
@@ -205,13 +212,11 @@ out:
int
lxc_abstract_unix_send_credential
(
int
fd
,
void
*
data
,
size_t
size
)
{
struct
msghdr
msg
=
{
0
};
struct
msghdr
msg
=
{
0
};
struct
iovec
iov
;
struct
cmsghdr
*
cmsg
;
struct
ucred
cred
=
{
.
pid
=
getpid
(),
.
uid
=
getuid
(),
.
gid
=
getgid
(),
.
pid
=
getpid
(),
.
uid
=
getuid
(),
.
gid
=
getgid
(),
};
char
cmsgbuf
[
CMSG_SPACE
(
sizeof
(
cred
))]
=
{
0
};
char
buf
[
1
]
=
{
0
};
...
...
@@ -238,7 +243,7 @@ int lxc_abstract_unix_send_credential(int fd, void *data, size_t size)
int
lxc_abstract_unix_rcv_credential
(
int
fd
,
void
*
data
,
size_t
size
)
{
struct
msghdr
msg
=
{
0
};
struct
msghdr
msg
=
{
0
};
struct
iovec
iov
;
struct
cmsghdr
*
cmsg
;
struct
ucred
cred
;
...
...
@@ -263,10 +268,11 @@ int lxc_abstract_unix_rcv_credential(int fd, void *data, size_t size)
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
if
(
cmsg
&&
cmsg
->
cmsg_len
==
CMSG_LEN
(
sizeof
(
struct
ucred
))
&&
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SCM_CREDENTIALS
)
{
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SCM_CREDENTIALS
)
{
memcpy
(
&
cred
,
CMSG_DATA
(
cmsg
),
sizeof
(
cred
));
if
(
cred
.
uid
&&
(
cred
.
uid
!=
getuid
()
||
cred
.
gid
!=
getgid
()))
{
if
(
cred
.
uid
&&
(
cred
.
uid
!=
getuid
()
||
cred
.
gid
!=
getgid
()))
{
INFO
(
"message denied for '%d/%d'"
,
cred
.
uid
,
cred
.
gid
);
return
-
EACCES
;
}
...
...
src/lxc/af_unix.h
View file @
cd64caf5
...
...
@@ -38,4 +38,4 @@ extern int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
extern
int
lxc_abstract_unix_send_credential
(
int
fd
,
void
*
data
,
size_t
size
);
extern
int
lxc_abstract_unix_rcv_credential
(
int
fd
,
void
*
data
,
size_t
size
);
#endif
#endif
/* __LXC_AF_UNIX_H */
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