X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Futil.c;h=f75df7b5116c68662decce5ac1f27a6a0897f0c6;hb=6f7f51f793e5f2a5d42e05e3f1e3101f49d37299;hp=278f0184de9f86ed9bce726d6ee201dfe7431202;hpb=4d6d6518c301c844be59c1b3a0d2092a3218572f;p=elogind.git diff --git a/src/util.c b/src/util.c index 278f0184d..f75df7b51 100644 --- a/src/util.c +++ b/src/util.c @@ -64,6 +64,9 @@ #include "exit-status.h" #include "hashmap.h" +int saved_argc = 0; +char **saved_argv = NULL; + size_t page_size(void) { static __thread size_t pgsz = 0; long r; @@ -3026,6 +3029,20 @@ void rename_process(const char name[8]) { if (program_invocation_name) strncpy(program_invocation_name, name, strlen(program_invocation_name)); + + if (saved_argc > 0) { + int i; + + if (saved_argv[0]) + strncpy(saved_argv[0], name, strlen(saved_argv[0])); + + for (i = 1; i < saved_argc; i++) { + if (!saved_argv[i]) + break; + + memset(saved_argv[i], 0, strlen(saved_argv[i])); + } + } } void sigset_add_many(sigset_t *ss, ...) { @@ -4674,7 +4691,11 @@ int vt_disallocate(const char *name) { if (fd < 0) return fd; - loop_write(fd, "\033[H\033[2J", 7, false); /* clear screen */ + loop_write(fd, + "\033[r" /* clear scrolling region */ + "\033[H" /* move home */ + "\033[2J", /* clear screen */ + 10, false); close_nointr_nofail(fd); return 0; @@ -4710,8 +4731,11 @@ int vt_disallocate(const char *name) { if (fd < 0) return fd; - /* Requires Linux 2.6.40 */ - loop_write(fd, "\033[H\033[3J", 7, false); /* clear screen including scrollback */ + loop_write(fd, + "\033[r" /* clear scrolling region */ + "\033[H" /* move home */ + "\033[3J", /* clear screen including scrollback, requires Linux 2.6.40 */ + 10, false); close_nointr_nofail(fd); return 0; @@ -5164,6 +5188,52 @@ int socket_from_display(const char *display, char **path) { return 0; } +int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home) { + struct passwd *p; + unsigned long lu; + + assert(username); + assert(*username); + assert(uid); + assert(gid); + assert(home); + + /* We enforce some special rules for uid=0: in order to avoid + * NSS lookups for root we hardcode its data. */ + + if (streq(*username, "root") || streq(*username, "0")) { + *username = "root"; + *uid = 0; + *gid = 0; + *home = "/root"; + return 0; + } + + if (safe_atolu(*username, &lu) >= 0) { + errno = 0; + p = getpwuid((uid_t) lu); + + /* If there are multiple users with the same id, make + * sure to leave $USER to the configured value instead + * of the first occurrence in the database. However if + * the uid was configured by a numeric uid, then let's + * pick the real username from /etc/passwd. */ + if (p) + *username = p->pw_name; + } else { + errno = 0; + p = getpwnam(*username); + } + + if (!p) + return errno != 0 ? -errno : -ESRCH; + + *uid = p->pw_uid; + *gid = p->pw_gid; + *home = p->pw_dir; + return 0; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",