basic: add RuntimeScope enum
In various tools and services we have a per-system and per-user concept. So far we sometimes used a boolean indicating whether we are in system mode, or a reversed boolean indicating whether we are in user mode, or the LookupScope enum used by the lookup path logic. Let's address that, in introduce a common enum for this, we can use all across the board. This is mostly just search/replace, no actual code changes.
This commit is contained in:
+12
-12
@@ -334,15 +334,15 @@ int specifier_os_image_version(char specifier, const void *data, const char *roo
|
||||
}
|
||||
|
||||
int specifier_group_name(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
|
||||
LookupScope scope = PTR_TO_INT(data);
|
||||
RuntimeScope scope = PTR_TO_INT(data);
|
||||
char *t;
|
||||
|
||||
assert(ret);
|
||||
|
||||
if (scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return -EINVAL;
|
||||
|
||||
t = gid_to_name(scope == LOOKUP_SCOPE_USER ? getgid() : 0);
|
||||
t = gid_to_name(scope == RUNTIME_SCOPE_USER ? getgid() : 0);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -351,15 +351,15 @@ int specifier_group_name(char specifier, const void *data, const char *root, con
|
||||
}
|
||||
|
||||
int specifier_group_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
|
||||
LookupScope scope = PTR_TO_INT(data);
|
||||
RuntimeScope scope = PTR_TO_INT(data);
|
||||
gid_t gid;
|
||||
|
||||
assert(ret);
|
||||
|
||||
if (scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return -EINVAL;
|
||||
|
||||
gid = scope == LOOKUP_SCOPE_USER ? getgid() : 0;
|
||||
gid = scope == RUNTIME_SCOPE_USER ? getgid() : 0;
|
||||
|
||||
if (asprintf(ret, UID_FMT, gid) < 0)
|
||||
return -ENOMEM;
|
||||
@@ -368,16 +368,16 @@ int specifier_group_id(char specifier, const void *data, const char *root, const
|
||||
}
|
||||
|
||||
int specifier_user_name(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
|
||||
LookupScope scope = PTR_TO_INT(data);
|
||||
RuntimeScope scope = PTR_TO_INT(data);
|
||||
uid_t uid;
|
||||
char *t;
|
||||
|
||||
assert(ret);
|
||||
|
||||
if (scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return -EINVAL;
|
||||
|
||||
uid = scope == LOOKUP_SCOPE_USER ? getuid() : 0;
|
||||
uid = scope == RUNTIME_SCOPE_USER ? getuid() : 0;
|
||||
|
||||
/* If we are UID 0 (root), this will not result in NSS, otherwise it might. This is good, as we want
|
||||
* to be able to run this in PID 1, where our user ID is 0, but where NSS lookups are not allowed.
|
||||
@@ -395,15 +395,15 @@ int specifier_user_name(char specifier, const void *data, const char *root, cons
|
||||
}
|
||||
|
||||
int specifier_user_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
|
||||
LookupScope scope = PTR_TO_INT(data);
|
||||
RuntimeScope scope = PTR_TO_INT(data);
|
||||
uid_t uid;
|
||||
|
||||
assert(ret);
|
||||
|
||||
if (scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return -EINVAL;
|
||||
|
||||
uid = scope == LOOKUP_SCOPE_USER ? getuid() : 0;
|
||||
uid = scope == RUNTIME_SCOPE_USER ? getuid() : 0;
|
||||
|
||||
if (asprintf(ret, UID_FMT, uid) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user