From: Lennart Poettering Date: Fri, 20 Jul 2018 09:36:10 +0000 (+0200) Subject: pam_systemd: move socket_from_display() from util.[ch] to pam_systemd.c X-Git-Tag: v240~895^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f7b8b5c4fb8bb6490160e2accb77a7aeaf952ddf;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/util.c b/src/basic/util.c index 8f2d6061da0..2206c1b4ad1 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -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; diff --git a/src/basic/util.h b/src/basic/util.h index 9699d228f9c..42c262f5983 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -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) diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 8c5afeb1f73..91802439e99 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -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,