pam_systemd: move socket_from_display() from util.[ch] to pam_systemd.c

It's highly specific, kinda legacy (X11…) and only used at one place,
let's move this out of the common code, and into pam_systemd.c where it
is used.
This commit is contained in:
Lennart Poettering
2018-07-20 11:36:10 +02:00
parent e37e5ed32e
commit f7b8b5c4fb
3 changed files with 25 additions and 26 deletions

View File

@@ -77,31 +77,6 @@ bool display_is_local(const char *display) {
display[1] <= '9';
}
int socket_from_display(const char *display, char **path) {
size_t k;
char *f, *c;
assert(display);
assert(path);
if (!display_is_local(display))
return -EINVAL;
k = strspn(display+1, "0123456789");
f = new(char, STRLEN("/tmp/.X11-unix/X") + k + 1);
if (!f)
return -ENOMEM;
c = stpcpy(f, "/tmp/.X11-unix/X");
memcpy(c, display+1, k);
c[k] = 0;
*path = f;
return 0;
}
bool kexec_loaded(void) {
_cleanup_free_ char *s = NULL;

View File

@@ -50,7 +50,6 @@ static inline const char* enable_disable(bool b) {
bool plymouth_running(void);
bool display_is_local(const char *display) _pure_;
int socket_from_display(const char *display, char **path);
#define NULSTR_FOREACH(i, l) \
for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)

View File

@@ -114,6 +114,31 @@ static int get_user_data(
return PAM_SUCCESS;
}
static int socket_from_display(const char *display, char **path) {
size_t k;
char *f, *c;
assert(display);
assert(path);
if (!display_is_local(display))
return -EINVAL;
k = strspn(display+1, "0123456789");
f = new(char, STRLEN("/tmp/.X11-unix/X") + k + 1);
if (!f)
return -ENOMEM;
c = stpcpy(f, "/tmp/.X11-unix/X");
memcpy(c, display+1, k);
c[k] = 0;
*path = f;
return 0;
}
static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) {
union sockaddr_union sa = {
.un.sun_family = AF_UNIX,