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
548b3229
Unverified
Commit
548b3229
authored
Apr 25, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
af_unix: backport helper functions
This backports various helpers associated with seccomp notify to make maintenance easier. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
85714791
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
af_unix.c
src/lxc/af_unix.c
+70
-0
af_unix.h
src/lxc/af_unix.h
+5
-0
No files found.
src/lxc/af_unix.c
View file @
548b3229
...
@@ -316,3 +316,73 @@ int lxc_abstract_unix_rcv_credential(int fd, void *data, size_t size)
...
@@ -316,3 +316,73 @@ int lxc_abstract_unix_rcv_credential(int fd, void *data, size_t size)
out:
out:
return
ret
;
return
ret
;
}
}
int
lxc_unix_sockaddr
(
struct
sockaddr_un
*
ret
,
const
char
*
path
)
{
size_t
len
;
len
=
strlen
(
path
);
if
(
len
==
0
)
return
minus_one_set_errno
(
EINVAL
);
if
(
path
[
0
]
!=
'/'
&&
path
[
0
]
!=
'@'
)
return
minus_one_set_errno
(
EINVAL
);
if
(
path
[
1
]
==
'\0'
)
return
minus_one_set_errno
(
EINVAL
);
if
(
len
+
1
>
sizeof
(
ret
->
sun_path
))
return
minus_one_set_errno
(
EINVAL
);
*
ret
=
(
struct
sockaddr_un
){
.
sun_family
=
AF_UNIX
,
};
if
(
path
[
0
]
==
'@'
)
{
memcpy
(
ret
->
sun_path
+
1
,
path
+
1
,
len
);
return
(
int
)(
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
);
}
memcpy
(
ret
->
sun_path
,
path
,
len
+
1
);
return
(
int
)(
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
}
int
lxc_unix_connect
(
struct
sockaddr_un
*
addr
)
{
__do_close_prot_errno
int
fd
=
-
EBADF
;
int
ret
;
ssize_t
len
;
fd
=
socket
(
PF_UNIX
,
SOCK_STREAM
,
SOCK_CLOEXEC
);
if
(
fd
<
0
)
return
-
1
;
if
(
addr
->
sun_path
[
0
]
==
'\0'
)
len
=
strlen
(
&
addr
->
sun_path
[
1
]);
else
len
=
strlen
(
&
addr
->
sun_path
[
0
]);
ret
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
);
if
(
ret
<
0
)
return
-
1
;
return
move_fd
(
fd
);
}
int
lxc_socket_set_timeout
(
int
fd
,
int
rcv_timeout
,
int
snd_timeout
)
{
struct
timeval
out
=
{
0
};
int
ret
;
out
.
tv_sec
=
snd_timeout
;
ret
=
setsockopt
(
fd
,
SOL_SOCKET
,
SO_SNDTIMEO
,
(
const
void
*
)
&
out
,
sizeof
(
out
));
if
(
ret
<
0
)
return
-
1
;
out
.
tv_sec
=
rcv_timeout
;
ret
=
setsockopt
(
fd
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
const
void
*
)
&
out
,
sizeof
(
out
));
if
(
ret
<
0
)
return
-
1
;
return
0
;
}
src/lxc/af_unix.h
View file @
548b3229
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
#define __LXC_AF_UNIX_H
#define __LXC_AF_UNIX_H
#include <stdio.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
/* does not enforce \0-termination */
/* does not enforce \0-termination */
extern
int
lxc_abstract_unix_open
(
const
char
*
path
,
int
type
,
int
flags
);
extern
int
lxc_abstract_unix_open
(
const
char
*
path
,
int
type
,
int
flags
);
...
@@ -37,5 +39,8 @@ extern int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
...
@@ -37,5 +39,8 @@ extern int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
void
*
data
,
size_t
size
);
void
*
data
,
size_t
size
);
extern
int
lxc_abstract_unix_send_credential
(
int
fd
,
void
*
data
,
size_t
size
);
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
);
extern
int
lxc_abstract_unix_rcv_credential
(
int
fd
,
void
*
data
,
size_t
size
);
extern
int
lxc_unix_sockaddr
(
struct
sockaddr_un
*
ret
,
const
char
*
path
);
extern
int
lxc_unix_connect
(
struct
sockaddr_un
*
addr
);
extern
int
lxc_socket_set_timeout
(
int
fd
,
int
rcv_timeout
,
int
snd_timeout
);
#endif
/* __LXC_AF_UNIX_H */
#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