]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/user-util.h
shared/user-util: add compat forms of user name checking functions
[thirdparty/systemd.git] / src / basic / user-util.h
index a18f4d6f1ac9f1fa1a62d02622f41790ed169902..cfa515f5e8a26be33e2a354dfc206ce84d91f170 100644 (file)
@@ -2,7 +2,9 @@
 #pragma once
 
 #include <grp.h>
+#if ENABLE_GSHADOW
 #include <gshadow.h>
+#endif
 #include <pwd.h>
 #include <shadow.h>
 #include <stdbool.h>
@@ -26,9 +28,9 @@ char* getlogname_malloc(void);
 char* getusername_malloc(void);
 
 typedef enum UserCredsFlags {
-        USER_CREDS_SYNTHESIZE_FALLBACK = 1 << 0,  /* if set, only synthesize user records if database lacks them. Normally we bypass the userdb entirely for the records we can synthesize */
-        USER_CREDS_ALLOW_MISSING       = 1 << 1,  /* if a numeric UID string is resolved, be OK if there's no record for it */
-        USER_CREDS_CLEAN               = 1 << 2,  /* try to clean up shell and home fields with invalid data */
+        USER_CREDS_PREFER_NSS    = 1 << 0,  /* if set, only synthesize user records if database lacks them. Normally we bypass the userdb entirely for the records we can synthesize */
+        USER_CREDS_ALLOW_MISSING = 1 << 1,  /* if a numeric UID string is resolved, be OK if there's no record for it */
+        USER_CREDS_CLEAN         = 1 << 2,  /* try to clean up shell and home fields with invalid data */
 } UserCredsFlags;
 
 int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell, UserCredsFlags flags);
@@ -83,8 +85,20 @@ static inline bool userns_supported(void) {
         return access("/proc/self/uid_map", F_OK) >= 0;
 }
 
-bool valid_user_group_name(const char *u);
-bool valid_user_group_name_or_id(const char *u);
+bool valid_user_group_name_full(const char *u, bool strict);
+bool valid_user_group_name_or_id_full(const char *u, bool strict);
+static inline bool valid_user_group_name(const char *u) {
+        return valid_user_group_name_full(u, true);
+}
+static inline bool valid_user_group_name_or_id(const char *u) {
+        return valid_user_group_name_or_id_full(u, true);
+}
+static inline bool valid_user_group_name_compat(const char *u) {
+        return valid_user_group_name_full(u, false);
+}
+static inline bool valid_user_group_name_or_id_compat(const char *u) {
+        return valid_user_group_name_or_id_full(u, false);
+}
 bool valid_gecos(const char *d);
 bool valid_home(const char *p);
 
@@ -111,3 +125,5 @@ int putgrent_sane(const struct group *gr, FILE *stream);
 int fgetsgent_sane(FILE *stream, struct sgrp **sg);
 int putsgent_sane(const struct sgrp *sg, FILE *stream);
 #endif
+
+int make_salt(char **ret);