/*
* Handle passwd entries via struct passwd
*
- * Copyright (C) 2019 Simon Ruderich
+ * Copyright (C) 2019-2021 Simon Ruderich
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
uint64_t uid;
uint64_t gid;
- // off_name = 0
+ // off_name = 0, not stored on disk
uint16_t off_passwd;
uint16_t off_gecos;
uint16_t off_dir;
uint16_t off_shell;
- uint16_t data_size;
/*
* Data contains all strings (name, passwd, gecos, dir, shell)
* concatenated, with their trailing NUL. The off_* variables point to
* beginning of each string.
*/
+ uint16_t data_size; // size of data in bytes
const char data[];
} __attribute__((packed));
};
static pthread_mutex_t static_file_lock = PTHREAD_MUTEX_INITIALIZER;
-enum nss_status _nss_cash_setpwent(int x) {
- (void)x;
-
+static void internal_unmap_static_file(void) {
pthread_mutex_lock(&static_file_lock);
- // Unmap is necessary to detect changes when the file was replaced on
- // disk
unmap_file(&static_file);
- // getpwent_r will open the file if necessary when called
pthread_mutex_unlock(&static_file_lock);
+}
+enum nss_status _nss_cash_setpwent(int x) {
+ (void)x;
+
+ // Unmap is necessary to detect changes when the file was replaced on
+ // disk; getpwent_r will open the file if necessary when called
+ internal_unmap_static_file();
return NSS_STATUS_SUCCESS;
}
enum nss_status _nss_cash_endpwent(void) {
- pthread_mutex_lock(&static_file_lock);
- unmap_file(&static_file);
- pthread_mutex_unlock(&static_file_lock);
-
+ internal_unmap_static_file();
return NSS_STATUS_SUCCESS;
}
return NSS_STATUS_NOTFOUND;
}
- const char *e = h->data + h->off_data + *off;
+ const char *e = key->data + *off;
if (!entry_to_passwd((struct passwd_entry *)e, result, buffer, buflen)) {
unmap_file(&f);
errno = ERANGE;
}
enum nss_status _nss_cash_getpwuid_r(uid_t uid, struct passwd *result, char *buffer, size_t buflen, int *errnop) {
- uint64_t id = (uint64_t)uid;
struct search_key key = {
- .id = &id,
+ .id = (uint64_t)uid,
.offset = offsetof(struct passwd_entry, uid),
};
return internal_getpw(&key, result, buffer, buflen, errnop);