Skip to contentSkip to conversation

Remove add_local/set_local

SEMANAGE(lib/tool) Ivan Gyurdiev 2 participants 4 messages Jan 9, 2006 – Jan 18, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi, this patch removes add_local and set_local functions from the dbase API, since they duplicate other functionality.

Set_local offers no benefits over modify_local coupled with an exists check - it takes the same amount of time, and the error path behavior isn't really useful, since the client should know whether an object exists or not in advance, and handle that case appropriately.

Same for add_local, unless the internal check for duplicate keys is removed, in which case it will have faster performance. However, I am thinking that the library must maintain the integrity of the store, so this optimization should not be made, since it can corrupt the store if the client is careless. Let me know if you disagree, I am not sure if removing add is a good idea or not...

========
This doesn't remove the dbase add or set capability, which are still used internally in several places (will have to take another look at those) - it just clears the API and manpages. The set_active function is kept. I also updated the semanage tool and pywrap-test.py. Note that the pywrap test update makes it work properly when the record being tested is already present in the local store (will reset it properly when the test is done).

libsemanage/include/semanage/booleans_local.h +0 -10
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/include/semanage/booleans_local.h new/libsemanage/include/semanage/booleans_local.h
@@ -7,21 +7,11 @@
 #include <semanage/boolean_record.h>
 #include <semanage/handle.h>
 
-extern int semanage_bool_add_local(
-	semanage_handle_t* handle,
-	const semanage_bool_key_t* key,
-	const semanage_bool_t* data);
-
 extern int semanage_bool_modify_local(
 	semanage_handle_t* handle,
 	const semanage_bool_key_t* key,
 	const semanage_bool_t* data);
 
-extern int semanage_bool_set_local(
-	semanage_handle_t* handle,
-	const semanage_bool_key_t* key,
-	const semanage_bool_t* data);
-
 extern int semanage_bool_del_local(
 	semanage_handle_t* handle,
 	const semanage_bool_key_t* key);
libsemanage/include/semanage/fcontexts_local.h +0 -10
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/include/semanage/fcontexts_local.h new/libsemanage/include/semanage/fcontexts_local.h
@@ -7,21 +7,11 @@
 #include <semanage/fcontext_record.h>
 #include <semanage/handle.h>
 
-extern int semanage_fcontext_add_local(
-	semanage_handle_t* handle,
-	const semanage_fcontext_key_t* key,
-	const semanage_fcontext_t* data);
-
 extern int semanage_fcontext_modify_local(
 	semanage_handle_t* handle,
 	const semanage_fcontext_key_t* key,
 	const semanage_fcontext_t* data);
 
-extern int semanage_fcontext_set_local(
-	semanage_handle_t* handle,
-	const semanage_fcontext_key_t* key,
-	const semanage_fcontext_t* data);
-
 extern int semanage_fcontext_del_local(
 	semanage_handle_t* handle,
 	const semanage_fcontext_key_t* key);
libsemanage/include/semanage/interfaces_local.h +0 -10
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/include/semanage/interfaces_local.h new/libsemanage/include/semanage/interfaces_local.h
@@ -7,21 +7,11 @@
 #include <semanage/iface_record.h>
 #include <semanage/handle.h>
 
-extern int semanage_iface_add_local(
-	semanage_handle_t* handle,
-	const semanage_iface_key_t* key,
-	const semanage_iface_t* data);
-
 extern int semanage_iface_modify_local(
 	semanage_handle_t* handle,
 	const semanage_iface_key_t* key,
 	const semanage_iface_t* data);
 
-extern int semanage_iface_set_local(
-	semanage_handle_t* handle,
-	const semanage_iface_key_t* key,
-	const semanage_iface_t* data);
-
 extern int semanage_iface_del_local(
 	semanage_handle_t* handle,
 	const semanage_iface_key_t* key);
libsemanage/include/semanage/ports_local.h +0 -10
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/include/semanage/ports_local.h new/libsemanage/include/semanage/ports_local.h
@@ -7,21 +7,11 @@
 #include <semanage/port_record.h>
 #include <semanage/handle.h>
 
-extern int semanage_port_add_local(
-	semanage_handle_t* handle,
-	const semanage_port_key_t* key,
-	const semanage_port_t* data);
-
 extern int semanage_port_modify_local(
 	semanage_handle_t* handle,
 	const semanage_port_key_t* key,
 	const semanage_port_t* data);
 
-extern int semanage_port_set_local(
-	semanage_handle_t* handle,
-	const semanage_port_key_t* key,
-	const semanage_port_t* data);
-
 extern int semanage_port_del_local(
 	semanage_handle_t* handle,
 	const semanage_port_key_t* key);
libsemanage/include/semanage/seusers.h +0 -10
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/include/semanage/seusers.h new/libsemanage/include/semanage/seusers.h
@@ -7,21 +7,11 @@
 #include <semanage/seuser_record.h>
 #include <semanage/handle.h>
 
-extern int semanage_seuser_add(
-	semanage_handle_t* handle,
-	const semanage_seuser_key_t* key,
-	const semanage_seuser_t* data);
-
 extern int semanage_seuser_modify(
 	semanage_handle_t* handle,
 	const semanage_seuser_key_t* key,
 	const semanage_seuser_t* data);
 
-extern int semanage_seuser_set(
-	semanage_handle_t* handle,
-	const semanage_seuser_key_t* key,
-	const semanage_seuser_t* data);
-
 extern int semanage_seuser_del(
 	semanage_handle_t* handle,
 	const semanage_seuser_key_t* key);
libsemanage/include/semanage/users_local.h +0 -10
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/include/semanage/users_local.h new/libsemanage/include/semanage/users_local.h
@@ -7,21 +7,11 @@
 #include <semanage/user_record.h>
 #include <semanage/handle.h>
 
-extern int semanage_user_add_local(
-	semanage_handle_t* handle,
-	const semanage_user_key_t* key,
-	const semanage_user_t* data);
-
 extern int semanage_user_modify_local(
 	semanage_handle_t* handle,
 	const semanage_user_key_t* key,
 	const semanage_user_t* data);
 
-extern int semanage_user_set_local(
-	semanage_handle_t* handle,
-	const semanage_user_key_t* key,
-	const semanage_user_t* data);
-
 extern int semanage_user_del_local(
 	semanage_handle_t* handle,
 	const semanage_user_key_t* key);
libsemanage/man/man3/semanage_bool_add_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_bool_add_local.3 new/libsemanage/man/man3/semanage_bool_add_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_add_local.3
libsemanage/man/man3/semanage_bool_set_active.3 +47 -1

48 lines not on this page · raw message

libsemanage/man/man3/semanage_bool_set_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_bool_set_local.3 new/libsemanage/man/man3/semanage_bool_set_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_set_local.3
libsemanage/man/man3/semanage_fcontext_add_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_fcontext_add_local.3 new/libsemanage/man/man3/semanage_fcontext_add_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_add_local.3
libsemanage/man/man3/semanage_fcontext_set_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_fcontext_set_local.3 new/libsemanage/man/man3/semanage_fcontext_set_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_set_local.3
libsemanage/man/man3/semanage_iface_add_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_iface_add_local.3 new/libsemanage/man/man3/semanage_iface_add_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_add_local.3
libsemanage/man/man3/semanage_iface_set_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_iface_set_local.3 new/libsemanage/man/man3/semanage_iface_set_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_set_local.3
libsemanage/man/man3/semanage_port_add_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_port_add_local.3 new/libsemanage/man/man3/semanage_port_add_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_add_local.3
libsemanage/man/man3/semanage_port_set_local.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_port_set_local.3 new/libsemanage/man/man3/semanage_port_set_local.3
@@ -1 +0,0 @@
-.so man3/semanage_user_set_local.3
libsemanage/man/man3/semanage_seuser_add.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_seuser_add.3 new/libsemanage/man/man3/semanage_seuser_add.3
@@ -1 +0,0 @@
-.so man3/semanage_user_add_local.3
libsemanage/man/man3/semanage_seuser_set.3 +0 -1
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_seuser_set.3 new/libsemanage/man/man3/semanage_seuser_set.3
@@ -1 +0,0 @@
-.so man3/semanage_user_set_local.3
libsemanage/man/man3/semanage_user_add_local.3 +0 -81

81 lines not on this page · raw message

libsemanage/man/man3/semanage_user_modify_local.3 +3 -6
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/man/man3/semanage_user_modify_local.3 new/libsemanage/man/man3/semanage_user_modify_local.3
@@ -16,7 +16,7 @@ add or update an interface in the local 
 add or override a context specification in the local store
 .br
 .B semanage_seuser_modify \- 
-add a new seuser (login mapping)
+add or update a seuser (login mapping)
 
 .SH "SYNOPSIS"
 .B #include <semanage/users_local.h> 
@@ -49,13 +49,10 @@ user, port, fcontext, iface, seuser
 
 .SH "DESCRIPTION"
 .TP
-.SS Modify Group:
-The group of modify functions are one of three ways to modify policy objects (the other two being the add group, and the set group). The three groups differ in whether they allow new or existing objects with respect to the local store. Behavior with respect to policy is the same - the object will be added if new, or changed if it exists (except for booleans, which do not allow new additions). Modify functions will update existing objects in the local store, and will also allow new objects.
-.TP
 .SS Behavior:
-If a matching key is found in the local store, the object provided will replace the current one. Otherwise, it will be added to the store, and later loaded into policy. Changes will become permanent when
+If a matching key is found in the local store, the provided object will replace the current one. Otherwise, it will be added to the store. When
 .B semanage_commit 
-is invoked. Validity of the object being added is checked at commit time. 
+is invoked, changes will be permanently written into the local store, and then loaded into policy. Validity of the object being added is checked at commit time. Adding new objects with respect to policy is allowed, except in the case of booleans. Attempt to add new booleans with respect to policy will fail at commit time.
 .TP
 .SS Parameters:
 The 
libsemanage/man/man3/semanage_user_set_local.3 +0 -86

86 lines not on this page · raw message

libsemanage/src/booleans_local.c +0 -18
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/src/booleans_local.c new/libsemanage/src/booleans_local.c
@@ -11,15 +11,6 @@ typedef struct semanage_bool record_t;
 #include "handle.h" 
 #include "database.h"
 
-int semanage_bool_add_local(
-	semanage_handle_t* handle,
-	const semanage_bool_key_t* key,
-	const semanage_bool_t* data) {
-
-	dbase_config_t* dconfig = semanage_bool_dbase_local(handle);
-	return dbase_add(handle, dconfig, key, data);
-}
-
 int semanage_bool_modify_local(
 	semanage_handle_t* handle,
 	const semanage_bool_key_t* key,
@@ -29,15 +20,6 @@ int semanage_bool_modify_local(
 	return dbase_modify(handle, dconfig, key, data);
 }
 
-int semanage_bool_set_local(
-	semanage_handle_t* handle,
-	const semanage_bool_key_t* key,
-	const semanage_bool_t* data) {
-
-	dbase_config_t* dconfig = semanage_bool_dbase_local(handle);	
-	return dbase_set(handle, dconfig, key, data);
-}
-
 int semanage_bool_del_local(
 	semanage_handle_t* handle,
 	const semanage_bool_key_t* key) {
libsemanage/src/fcontexts_local.c +0 -18
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/src/fcontexts_local.c new/libsemanage/src/fcontexts_local.c
@@ -16,15 +16,6 @@ typedef struct semanage_fcontext record_
 #include "handle.h" 
 #include "database.h"
 
-int semanage_fcontext_add_local(
-	semanage_handle_t* handle,
-	const semanage_fcontext_key_t* key,
-	const semanage_fcontext_t* data) {
-
-	dbase_config_t* dconfig = semanage_fcontext_dbase_local(handle);
-	return dbase_add(handle, dconfig, key, data);
-}
-
 int semanage_fcontext_modify_local(
 	semanage_handle_t* handle,
 	const semanage_fcontext_key_t* key,
@@ -34,15 +25,6 @@ int semanage_fcontext_modify_local(
 	return dbase_modify(handle, dconfig, key, data);
 }
 
-int semanage_fcontext_set_local(
-	semanage_handle_t* handle,
-	const semanage_fcontext_key_t* key,
-	const semanage_fcontext_t* data) {
-
-	dbase_config_t* dconfig = semanage_fcontext_dbase_local(handle);	
-	return dbase_set(handle, dconfig, key, data);
-}
-
 int semanage_fcontext_del_local(
 	semanage_handle_t* handle,
 	const semanage_fcontext_key_t* key) {
libsemanage/src/interfaces_local.c +0 -18
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/src/interfaces_local.c new/libsemanage/src/interfaces_local.c
@@ -11,15 +11,6 @@ typedef struct semanage_iface record_t;
 #include "handle.h" 
 #include "database.h"
 
-int semanage_iface_add_local(
-	semanage_handle_t* handle,
-	const semanage_iface_key_t* key,
-	const semanage_iface_t* data) {
-
-	dbase_config_t* dconfig = semanage_iface_dbase_local(handle);
-	return dbase_add(handle, dconfig, key, data);
-}
-
 int semanage_iface_modify_local(
 	semanage_handle_t* handle,
 	const semanage_iface_key_t* key,
@@ -29,15 +20,6 @@ int semanage_iface_modify_local(
 	return dbase_modify(handle, dconfig, key, data);
 }
 
-int semanage_iface_set_local(
-	semanage_handle_t* handle,
-	const semanage_iface_key_t* key,
-	const semanage_iface_t* data) {
-
-	dbase_config_t* dconfig = semanage_iface_dbase_local(handle);	
-	return dbase_set(handle, dconfig, key, data);
-}
-
 int semanage_iface_del_local(
 	semanage_handle_t* handle,
 	const semanage_iface_key_t* key) {
libsemanage/src/pywrap-test.py +97 -31

204 lines not on this page · raw message

libsemanage/src/seusers.c +0 -18
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/src/seusers.c new/libsemanage/src/seusers.c
@@ -15,15 +15,6 @@ typedef struct semanage_seuser record_t;
 #include "database.h"
 #include "debug.h"
 
-int semanage_seuser_add(
-	semanage_handle_t* handle,
-	const semanage_seuser_key_t* key,
-	const semanage_seuser_t* data) {
-
-	dbase_config_t* dconfig = semanage_seuser_dbase(handle);
-	return dbase_add(handle, dconfig, key, data);
-}
-
 int semanage_seuser_modify(
 	semanage_handle_t* handle,
 	const semanage_seuser_key_t* key,
@@ -33,15 +24,6 @@ int semanage_seuser_modify(
 	return dbase_modify(handle, dconfig, key, data);
 }
 
-int semanage_seuser_set(
-	semanage_handle_t* handle,
-	const semanage_seuser_key_t* key,
-	const semanage_seuser_t* data) {
-
-	dbase_config_t* dconfig = semanage_seuser_dbase(handle);
-	return dbase_set(handle, dconfig, key, data);
-}
-
 int semanage_seuser_del(
 	semanage_handle_t* handle,
 	const semanage_seuser_key_t* key) {
libsemanage/src/users_local.c +0 -19
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/src/users_local.c new/libsemanage/src/users_local.c
@@ -11,15 +11,6 @@ typedef struct semanage_user record_t;
 #include "handle.h" 
 #include "database.h"
 
-int semanage_user_add_local(
-	semanage_handle_t* handle,
-	const semanage_user_key_t* key,
-	const semanage_user_t* data) {
-
-	dbase_config_t* dconfig = semanage_user_dbase_local(handle);
-	return dbase_add(handle, dconfig, key, data);
-}
-
 int semanage_user_modify_local(
 	semanage_handle_t* handle,
 	const semanage_user_key_t* key,
@@ -29,16 +20,6 @@ int semanage_user_modify_local(
 	return dbase_modify(handle, dconfig, key, data);
 }
 
-
-int semanage_user_set_local(
-	semanage_handle_t* handle,
-	const semanage_user_key_t* key,
-	const semanage_user_t* data) {
-
-	dbase_config_t* dconfig = semanage_user_dbase_local(handle);	
-	return dbase_set(handle, dconfig, key, data);
-}
-
 int semanage_user_del_local(
 	semanage_handle_t* handle,
 	const semanage_user_key_t* key) {
policycoreutils/semanage/semanage +2 -2
diff -Naurp --exclude ports_local.c --exclude-from excludes old/policycoreutils/semanage/semanage new/policycoreutils/semanage/semanage
@@ -145,7 +145,7 @@ class seluserRecords:
 			raise ValueError("Could not extract key for %s" % name)
 
 		semanage_begin_transaction(self.sh)
-		semanage_user_add_local(self.sh, k, u)
+		semanage_user_modify_local(self.sh, k, u)
 		if semanage_commit(self.sh) < 0:
 			raise ValueError("Failed to add SELinux user")
 
@@ -275,7 +275,7 @@ class portRecords:
 		semanage_context_set_mls(self.sh, con, serange)
 		semanage_port_set_con(p, con)
 		semanage_begin_transaction(self.sh)
-		semanage_port_add_local(self.sh, k, p)
+		semanage_port_modify_local(self.sh, k, p)
 		if semanage_commit(self.sh) < 0:
 			raise ValueError("Failed to add port")
 
#1 lore raw
Quoted 2 lines · Ivan Gyurdiev

Hi, this patch removes add_local and set_local functions from the dbase API, since they duplicate other functionality.

Merged as of libsemanage 1.5.12 and policycoreutils 1.29.6. I then later had to move the semanage tool diffs over to the new seobject.py introduced by Dan in a later policycoreutils.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
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 9 lines · Stephen Smalley
Quoted 2 lines · Ivan Gyurdiev

Hi, this patch removes add_local and set_local functions from the dbase API, since they duplicate other functionality.

Merged as of libsemanage 1.5.12 and policycoreutils 1.29.6. I then later had to move the semanage tool diffs over to the new seobject.py introduced by Dan in a later policycoreutils.

Steven, will you be increasing the major number with the next official release? Some of the changes made are suspect API changes (size_t conversion in sepol/semanage, commit numbers in semanage, compare behavior in sepol/semanage), and this one is a clear change... What about sepol?

If the number will be increased, I'll change some other not-so-smart APIs, like port_get_proto_str, and fcontext_get_proto_str, which should take an integer, and return a string, instead of taking a port or context. We could also deprecate some things in sepol, or add more handles here and there.

--
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.

#3 lore raw
Quoted 5 lines · Ivan Gyurdiev

Steven, will you be increasing the major number with the next official release? Some of the changes made are suspect API changes (size_t conversion in sepol/semanage, commit numbers in semanage, compare behavior in sepol/semanage), and this one is a clear change... What about sepol?

I'd prefer not to do so, as that will cause a non-trivial amount of pain and so far I don't think that we have affected anything outside of core SELinux code that we maintain ourselves, and I don't think that there will be any significant development of third party code against these libsepol and libsemanage interfaces until there is a stable Linux distribution release that includes them.

Quoted 5 lines

If the number will be increased, I'll change some other not-so-smart APIs, like port_get_proto_str, and fcontext_get_proto_str, which should take an integer, and return a string, instead of taking a port or context. We could also deprecate some things in sepol, or add more handles here and there.

To the extent that such APIs are only used by code we maintain ourselves, this is likely fine, and the interfaces you list above weren't even exported in the last nsa.gov release IIRC, much less a stable Linux distribution release.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
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.