// Preloaded into slock, which then runs as its user instead of root: // getspnam returns the password hash from the credential hashed-password, // and dropping privileges does nothing. #include #include #include #include #include static char hash[4096]; static struct spwd entry = { .sp_namp = "", .sp_pwdp = hash, }; struct spwd *getspnam(const char *name) { (void) name; const char *dir = getenv("CREDENTIALS_DIRECTORY"); char path[4096]; if (dir == NULL || snprintf(path, sizeof path, "%s/hashed-password", dir) >= (int) sizeof path) { return NULL; } FILE *f = fopen(path, "r"); if (f == NULL) { return NULL; } char *line = fgets(hash, sizeof hash, f); fclose(f); if (line == NULL) { return NULL; } hash[strcspn(hash, "\n")] = '\0'; return &entry; } int setgroups(size_t size, const gid_t *list) { (void) size; (void) list; return 0; } int setgid(gid_t gid) { (void) gid; return 0; } int setuid(uid_t uid) { (void) uid; return 0; }