Skip to contentSkip to conversation

Users

PATCH In review Ivan Gyurdiev 2 participants 3 messages Jul 21, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 3/6 Users

The following patch is intended to replace genusers.c (but not yet). It provides functions to add, delete and load users into a policydb object. It uses a structure (sepol_uinfo_t) as the higher level representation for a user, and takes out the parsing.

libsepol-2.1-users.diff

Disclaimer 1:
The role list must be NULL terminated.

Disclaimer 2:
Not sure MLS processing is correct - please take a look.

include/sepol/users.h +53 -0
diff -aru libsepol.work/include/sepol/users.h libsepol-2.1-users/include/sepol/users.h
@@ -0,0 +1,53 @@
+#ifndef _SEPOL_USERS_H_
+#define _SEPOL_USERS_H_
+
+#include <sepol/policydb.h>
+#include <sys/types.h>
+
+/* High level representation of a user */
+typedef struct sepol_uinfo {
+	const char* name;
+	const char** roles;
+	const char* mls_level;
+	const char* mls_range;
+} sepol_uinfo_t;
+
+/* Clear unused users */
+extern void sepol_clear_unused_users(
+	policydb_t* policydb);
+
+/* Add/delete/load users from the policy 
+   Load allows duplicates, but add does not. */
+extern int sepol_user_add(
+	policydb_t* policydb,
+	sepol_uinfo_t* user); 
+
+extern int sepol_user_del(
+	policydb_t* policydb, 
+	const char *username);
+
+extern int sepol_user_load(
+	policydb_t* policydb, 
+	sepol_uinfo_t* user);
+
+/* Check if users or roles are valid */
+extern int sepol_user_is_valid(
+	policydb_t* policydb,
+	const char* user);
+
+extern int sepol_role_is_valid(
+	policydb_t* policydb,
+	const char* role);
+
+/* Obtain an array of all valid users/roles */
+extern int sepol_get_valid_users(
+	policydb_t* policydb,
+	char*** users,
+	size_t* nusers);
+
+extern int sepol_get_valid_roles(
+	policydb_t* policydb, 
+	char*** roles, 
+	size_t* nroles);
+
+#endif /* _SEPOL_USERS_H_ */
src/genusers.c +2 -7
diff -aru libsepol.work/src/genusers.c libsepol-2.1-users/src/genusers.c
@@ -30,12 +30,7 @@
 	}
 }
 
-static int delusers = 0;
-
-void sepol_set_delusers(int on)
-{
-	delusers = on;
-}
+extern int selinux_delusers;
 
 #undef BADLINE
 #define BADLINE() { \
@@ -382,7 +377,7 @@
 		goto err;
 	}
 
-	if (delusers) {
+	if (selinux_delusers) {
 		/* Kill unused users and remap to avoid holes. */
 		ebitmap_init(&free_users);
 		kud.policydb = &policydb;
src/users.c +413 -0

413 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Ivan Gyurdiev

The following patch is intended to replace
genusers.c (but not yet). It provides functions to add, delete and load users into a policydb object. It uses a structure (sepol_uinfo_t) as the
higher level representation for a user, and
takes out the parsing.

Quoted 7 lines

libsepol-2.1-users.diff

Disclaimer 1:
The role list must be NULL terminated.

The libsemanage api I'm writing right now has num_roles, IMO better than null termination in that it's easier to make mistakes with null termination

struct semanage_user {
       char *name;             /* Key */
       struct semanage_role **roles;
       int num_roles;
       struct semanage_mls *mls;
}
Quoted 5 lines

Disclaimer 2:
Not sure MLS processing is correct - please
take a look.

I've been talking to the TCS guys while here about the right thing to do with MLS so the libsemanage api should be correct.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 3 lines

The libsemanage api I'm writing right now has num_roles, IMO better than null termination in that it's easier to make mistakes with null termination

Attached is a new version with num_roles.

include/sepol/users.h +54 -0
diff -p -aru libsepol.work/include/sepol/users.h libsepol-2.1-users/include/sepol/users.h
@@ -0,0 +1,54 @@
+#ifndef _SEPOL_USERS_H_
+#define _SEPOL_USERS_H_
+
+#include <sepol/policydb.h>
+#include <sys/types.h>
+
+/* High level representation of a user */
+typedef struct sepol_uinfo {
+	const char* name;
+	const char** roles;
+	size_t num_roles;
+	const char* mls_level;
+	const char* mls_range;
+} sepol_uinfo_t;
+
+/* Clear unused users */
+extern void sepol_clear_unused_users(
+	policydb_t* policydb);
+
+/* Add/delete/load users from the policy 
+   Load allows duplicates, but add does not. */
+extern int sepol_user_add(
+	policydb_t* policydb,
+	sepol_uinfo_t* user); 
+
+extern int sepol_user_del(
+	policydb_t* policydb, 
+	const char *username);
+
+extern int sepol_user_load(
+	policydb_t* policydb, 
+	sepol_uinfo_t* user);
+
+/* Check if users or roles are valid */
+extern int sepol_user_is_valid(
+	policydb_t* policydb,
+	const char* user);
+
+extern int sepol_role_is_valid(
+	policydb_t* policydb,
+	const char* role);
+
+/* Obtain an array of all valid users/roles */
+extern int sepol_get_valid_users(
+	policydb_t* policydb,
+	char*** users,
+	size_t* nusers);
+
+extern int sepol_get_valid_roles(
+	policydb_t* policydb, 
+	char*** roles, 
+	size_t* nroles);
+
+#endif /* _SEPOL_USERS_H_ */
src/genusers.c +2 -7
diff -p -aru libsepol.work/src/genusers.c libsepol-2.1-users/src/genusers.c
@@ -30,12 +30,7 @@ void __sepol_debug_printf(const char *fm
 	}
 }
 
-static int delusers = 0;
-
-void sepol_set_delusers(int on)
-{
-	delusers = on;
-}
+extern int selinux_delusers;
 
 #undef BADLINE
 #define BADLINE() { \
@@ -382,7 +377,7 @@ int sepol_genusers(void *data, size_t le
 		goto err;
 	}
 
-	if (delusers) {
+	if (selinux_delusers) {
 		/* Kill unused users and remap to avoid holes. */
 		ebitmap_init(&free_users);
 		kud.policydb = &policydb;
src/users.c +413 -0

413 lines not on this page · raw message