Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
APK Foundry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Max Rees
APK Foundry
Commits
27e38530
Verified
Commit
27e38530
authored
4 years ago
by
Max Rees
Browse files
Options
Downloads
Patches
Plain Diff
Remove dependency on skalibs
parent
490f557b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+1
-2
1 addition, 2 deletions
Makefile
README.rst
+2
-3
2 additions, 3 deletions
README.rst
af-req-root.c
+28
-26
28 additions, 26 deletions
af-req-root.c
with
31 additions
and
31 deletions
Makefile
+
1
−
2
View file @
27e38530
...
...
@@ -8,7 +8,6 @@ LOCALSTATEDIR = var/lib/apkfoundry
export
SYSCONFDIR
LIBEXECDIR
DOCDIR
LIBS
=
-lskarnet
PYTHON
=
python3
PYLINT
=
pylint
...
...
@@ -26,7 +25,7 @@ all: libexec/af-req-root
$(
PYTHON
)
setup.py build
libexec/af-req-root
:
af-req-root.c
$(
CC
)
$(
CFLAGS
)
-static-pie
$(
LDFLAGS
)
-o
$@
$<
$(
LIBS
)
$(
CC
)
$(
CFLAGS
)
-static-pie
$(
LDFLAGS
)
-o
$@
$<
.PHONY
:
install
install
:
all paths
...
...
This diff is collapsed.
Click to expand it.
README.rst
+
2
−
3
View file @
27e38530
...
...
@@ -14,12 +14,11 @@ Dependencies
------------
* Python 3.6+
* GitLab runner (optional - supported integration)
* `apk-tools <https://gitlab.alpinelinux.org/alpine/apk-tools>`_
(``apk.static`` only)
* `bubblewrap <https://github.com/containers/bubblewrap>`_ (installed as
non-setuid)
* Linux kernel with unprivileged user namespace support
* `shadow-uidmap <https://github.com/shadow-maint/shadow>`_
* `skalibs <https://skarnet.org/software/skalibs>`_ (build-time only
for statically-compiled helper program
)
* GitLab runner (optional - supported integration
)
This diff is collapsed.
Click to expand it.
af-req-root.c
+
28
−
26
View file @
27e38530
...
...
@@ -3,45 +3,47 @@
* Copyright (c) 2019-2020 Max Rees
* See LICENSE for more information.
*/
char
const
*
PROG
=
"af-req-root"
;
char
const
*
USAGE
=
"af-req-root
COMMAND [ARGS ...]"
;
#define
PROG "af-req-root"
#define USAGE PROG "
COMMAND [ARGS ...]"
#define BUF_SIZE 4096
#define NUM_FDS 3
#include
<errno.h>
/* errno */
#include
<libgen.h>
/* basename */
#include
<stdlib.h>
/* getenv, strtol */
#include
<stdio.h>
/* snprintf */
#include
<string.h>
/* memcpy */
#include
<sys/socket.h>
/* sendmsg */
#include
<unistd.h>
/* *_FILENO */
#include
<skalibs/bytestr.h>
/* str_equal */
#include
<skalibs/strerr2.h>
/* strerr_* */
#include
<skalibs/webipc.h>
/* ipc_connect */
#define _XOPEN_SOURCE 700
#include
<err.h>
/* err, errx */
#include
<errno.h>
/* errno */
#include
<libgen.h>
/* basename */
#include
<stdlib.h>
/* getenv, strtol */
#include
<stdio.h>
/* snprintf */
#include
<string.h>
/* memcpy, strcmp */
#include
<sys/socket.h>
#include
<unistd.h>
/* *_FILENO */
#define FATAL_IF(what, why) \
errno = 0; \
if (what) \
strerr_diefu1x(errno, why);
err(3, "%s", why);
static
void
usage
(
void
)
{
errx
(
1
,
"usage: %s"
,
USAGE
);
}
int
fd_from_env
(
char
*
name
)
{
static
int
fd_from_env
(
char
*
name
)
{
int
fd
;
char
*
value
;
value
=
getenv
(
name
);
if
(
value
==
0
)
strerr_die
notset
(
1
,
name
);
errx
(
1
,
"%s is
not
set
"
,
name
);
errno
=
0
;
fd
=
(
int
)
strtol
(
value
,
0
,
10
);
if
(
errno
!=
0
)
strerr_diein
valid
(
1
,
name
);
errx
(
1
,
"%s=%s is not a
valid
FD"
,
name
,
value
);
return
fd
;
}
void
send_cmd
(
int
sock_fd
,
int
my_fds
[
NUM_FDS
],
int
argc
,
int
start
,
char
*
argv
[])
{
static
void
send_cmd
(
int
sock_fd
,
int
my_fds
[
NUM_FDS
],
int
argc
,
int
start
,
char
*
argv
[])
{
char
buf
[
BUF_SIZE
];
int
i
,
written
,
remaining
,
added
;
struct
iovec
iov
;
...
...
@@ -54,9 +56,9 @@ void send_cmd(int sock_fd, int my_fds[NUM_FDS], int argc, int start, char *argv[
remaining
=
BUF_SIZE
-
written
;
added
=
snprintf
(
buf
+
written
,
remaining
,
"%s"
,
argv
[
i
])
+
1
;
if
(
added
>=
remaining
)
strerr_dief1x
(
2
,
"argv too long"
);
errx
(
2
,
"argv length exceeds maximum size of %d"
,
BUF_SIZE
);
else
if
(
added
<
0
)
strerr_diefu1x
(
3
,
"
snprintf
argv
"
);
err
(
3
,
"send_cmd
snprintf"
);
written
+=
added
;
}
...
...
@@ -78,14 +80,14 @@ void send_cmd(int sock_fd, int my_fds[NUM_FDS], int argc, int start, char *argv[
cmsg
->
cmsg_type
=
SCM_RIGHTS
;
memcpy
(
CMSG_DATA
(
cmsg
),
my_fds
,
NUM_FDS
*
sizeof
(
int
));
FATAL_IF
(
sendmsg
(
sock_fd
,
&
msg
,
0
)
==
-
1
,
"send
cmd"
);
FATAL_IF
(
sendmsg
(
sock_fd
,
&
msg
,
0
)
==
-
1
,
"send
_
cmd
sendmsg
"
);
}
int
recv_retcode
(
int
sock_fd
)
{
static
int
recv_retcode
(
int
sock_fd
)
{
char
buf
[
BUF_SIZE
];
int
*
rc
;
FATAL_IF
(
recv
(
sock_fd
,
buf
,
BUF_SIZE
,
0
)
==
-
1
,
"rec
eive
retcode"
);
FATAL_IF
(
recv
(
sock_fd
,
buf
,
BUF_SIZE
,
0
)
==
-
1
,
"rec
v_
retcode
recv
"
);
rc
=
(
int
*
)
buf
;
return
*
rc
;
}
...
...
@@ -96,16 +98,16 @@ int main(int argc, char *argv[]) {
int
my_fds
[
NUM_FDS
]
=
{
STDIN_FILENO
,
STDOUT_FILENO
,
STDERR_FILENO
};
if
(
argc
==
0
)
strerr_dieusage
(
1
,
USAGE
);
usage
(
);
cmd
=
basename
(
argv
[
0
]);
if
(
str
_equal
(
cmd
,
PROG
))
if
(
str
cmp
(
cmd
,
PROG
)
==
0
)
start
=
1
;
else
start
=
0
;
if
(
argc
-
start
==
0
)
strerr_dieusage
(
1
,
USAGE
);
usage
(
);
sock_fd
=
fd_from_env
(
"AF_ROOT_FD"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment