Skip to contentSkip to conversation

Use PyList in bindings

SEMANAGE Ivan Gyurdiev 3 participants 10 messages Feb 2, 2006 – Feb 14, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

Okay, this patch is being the subject of controversy on IRC, so I wanted to continue discussion on-list.

It's an API change in the python bindings only, which converts out-bound arrays of objects (port, iface, boolean, etc..) to a PyList, which makes them easier to work with, and better integrated with the target language. Also, it fixes memory leak of the list structure (otherwise we have to expose free() to address that). It eliminates the need for get_by_idx functions, which are not really part of the libsemanage API.

Some problems w/ patch - it relies on some internal swig things - like the output variable being called result (swig provides $result, but that's in python, and I don't want to unpack it). Not sure if that's a problem, I'm not sure this t_output_helper business is part of the official API either. Also, swig is not very intelligent, and wants all the argument names to match (despite the docs saying otherwise).

Joshua doesn't like it..says semanage.i should be portable to other languages. However, I like better integration w/ python, so I think in that case maybe it makes sense to have several .i files. Also, I'm not sure the .i file is language portable right now - what will happen in a language that doesn't support an output vector, so adding things to result w/ t_output_helper doesn't necessarily make sense?

Also, how do I implement a binding for set_roles()? I want to unpack a PyList into a char** array - requires understanding of python in the .i file.

libsemanage/include/semanage/booleans_policy.h +1 -1
diff -Naurp --exclude-from excludes old/libsemanage/include/semanage/booleans_policy.h new/libsemanage/include/semanage/booleans_policy.h
@@ -30,6 +30,6 @@ extern int semanage_bool_iterate(
 extern int semanage_bool_list(
 	semanage_handle_t* handle,
 	semanage_bool_t*** records,
-	unsigned int* size);
+	unsigned int* count);
 
 #endif
libsemanage/src/pywrap-test.py +23 -51

177 lines not on this page · raw message

libsemanage/src/semanageswig.i +94 -34

171 lines not on this page · raw message

policycoreutils/scripts/genhomedircon +4 -6
diff -Naurp --exclude-from excludes old/policycoreutils/scripts/genhomedircon new/policycoreutils/scripts/genhomedircon
@@ -135,7 +135,7 @@ class selinuxConfig:
 		self.semanaged=semanage_is_managed(self.semanageHandle)
 		if self.semanaged:
 			semanage_connect(self.semanageHandle)
-			(status, self.ulist, self.usize) = semanage_user_list(self.semanageHandle)
+			(status, self.ulist) = semanage_user_list(self.semanageHandle)
 		self.type=type
 		self.selinuxdir=selinuxdir +"/"
 		self.contextdir="/contexts"
@@ -176,8 +176,7 @@ class selinuxConfig:
 		return ret
 
 	def defaultrole(self, name):
-		for idx in range(self.usize):
-			user = semanage_user_by_idx(self.ulist, idx)
+		for user in self.ulist:
 			if semanage_user_get_name(user) == name:
 				if name == "staff_u" or name == "root" and self.type != "targeted":
 					return "staff_r"
@@ -224,10 +223,9 @@ class selinuxConfig:
 	def getUsers(self):
 		udict = {}
 		if self.semanaged:
-			(status, list, lsize) = semanage_seuser_list(self.semanageHandle)
-			for idx in range(lsize):
+			(status, list) = semanage_seuser_list(self.semanageHandle)
+			for seuser in list:
 				user=[]
-				seuser = semanage_seuser_by_idx(list, idx)
 				seusername=semanage_seuser_get_sename(seuser)
 				self.adduser(udict, semanage_seuser_get_name(seuser), seusername, self.defaultrole(seusername))
 				
policycoreutils/semanage/seobject.py +14 -21
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/seobject.py new/policycoreutils/semanage/seobject.py
@@ -288,12 +288,11 @@ class loginRecords(semanageRecords):
 		
 	def get_all(self):
 		ddict={}
-		(rc, self.ulist, self.usize) = semanage_seuser_list(self.sh)
+		(rc, self.ulist) = semanage_seuser_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list login mappings")
 
-		for idx in range(self.usize):
-			u = semanage_seuser_by_idx(self.ulist, idx)
+		for u in self.ulist:
 			name = semanage_seuser_get_name(u)
 			ddict[name]=(semanage_seuser_get_sename(u), semanage_seuser_get_mlsrange(u))
 		return ddict
@@ -447,12 +446,11 @@ class seluserRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.ulist, self.usize) = semanage_user_list(self.sh)
+		(rc, self.ulist) = semanage_user_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list SELinux users")
 
-		for idx in range(self.usize):
-			u = semanage_user_by_idx(self.ulist, idx)
+		for u in self.ulist:
 			name = semanage_user_get_name(u)
 			(rc, rlist, rlist_size) = semanage_user_get_roles(self.sh, u)
 			if rc < 0:
@@ -637,12 +635,11 @@ class portRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_port_list(self.sh)
+		(rc, self.plist) = semanage_port_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list ports")
 
-		for idx in range(self.psize):
-			port = semanage_port_by_idx(self.plist, idx)
+		for port in self.plist:
 			con = semanage_port_get_con(port)
 			ctype = semanage_context_get_type(con)
 			if ctype == "reserved_port_t":
@@ -657,12 +654,11 @@ class portRecords(semanageRecords):
 
 	def get_all_by_type(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_port_list(self.sh)
+		(rc, self.plist) = semanage_port_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list ports")
 
-		for idx in range(self.psize):
-			port = semanage_port_by_idx(self.plist, idx)
+		for port in self.plist:
 			con = semanage_port_get_con(port)
 			ctype = semanage_context_get_type(con)
 			if ctype == "reserved_port_t":
@@ -837,12 +833,11 @@ class interfaceRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_iface_list(self.sh)
+		(rc, self.ilist) = semanage_iface_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list interfaces")
 
-		for idx in range(self.psize):
-			interface = semanage_iface_by_idx(self.plist, idx)
+		for interface in self.ilist:
 			con = semanage_iface_get_ifcon(interface)
 			ddict[semanage_iface_get_name(interface)]=(semanage_context_get_user(con), semanage_context_get_role(con), semanage_context_get_type(con), semanage_context_get_mls(con))
 
@@ -1022,12 +1017,11 @@ class fcontextRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_fcontext_list(self.sh)
+		(rc, self.flist) = semanage_fcontext_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list file contexts")
 
-		for idx in range(self.psize):
-			fcontext = semanage_fcontext_by_idx(self.plist, idx)
+		for fcontext in self.flist:
 			expr = semanage_fcontext_get_expr(fcontext)
 			ftype = semanage_fcontext_get_type(fcontext)
 			ftype_str = semanage_fcontext_get_type_str(ftype)
@@ -1124,12 +1118,11 @@ class booleanRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.blist, self.bsize) = semanage_bool_list(self.sh)
+		(rc, self.blist) = semanage_bool_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list booleans")
 
-		for idx in range(self.bsize):
-			boolean = semanage_bool_by_idx(self.blist, idx)
+		for boolean in self.blist:
 			name = semanage_bool_get_name(boolean)
 			value = semanage_bool_get_value(boolean)
 			ddict[name] = value
#1 lore raw

On the same note, this patch fixes a memory leak in the wrapper for things like:
semanage_context_to_string.

It's most likely language-portable (SWIG_FromCharPtr marks argument as const).

libsemanage/src/semanageswig.i +1 -0
diff -Naurp --exclude-from excludes old/libsemanage/src/semanageswig.i new/libsemanage/src/semanageswig.i
@@ -69,6 +69,7 @@
 
 %typemap(argout) char** {
 	$result = t_output_helper($result, SWIG_FromCharPtr(*$1));
+	free(*$1);
 }
 
 %typemap(in, numinputs=0) char ***(char **temp) {
#2 lore raw
In reply to Ivan Gyurdiev
Quoted 24 lines · Ivan Gyurdiev

Okay, this patch is being the subject of controversy on IRC, so I wanted to continue discussion on-list.

It's an API change in the python bindings only, which converts out-bound arrays of objects (port, iface, boolean, etc..) to a PyList, which makes them easier to work with, and better integrated with the target language. Also, it fixes memory leak of the list structure (otherwise we have to expose free() to address that). It eliminates the need for get_by_idx functions, which are not really part of the libsemanage API.

Some problems w/ patch - it relies on some internal swig things - like the output variable being called result (swig provides $result, but that's in python, and I don't want to unpack it). Not sure if that's a problem, I'm not sure this t_output_helper business is part of the official API either. Also, swig is not very intelligent, and wants all the argument names to match (despite the docs saying otherwise).

Joshua doesn't like it..says semanage.i should be portable to other languages. However, I like better integration w/ python, so I think in that case maybe it makes sense to have several .i files. Also, I'm not sure the .i file is language portable right now - what will happen in a language that doesn't support an output vector, so adding things to result w/ t_output_helper doesn't necessarily make sense?

Quoted 3 lines

Also, how do I implement a binding for set_roles()? I want to unpack a PyList into a char** array - requires understanding of python in the .i file.

Abstractly (while confessing total ignorance of swig), I would agree that we shouldn't cripple the python bindings for libsemanage just to allow a single interface file to be re-useable for other bindings. That said, I'm a little hesitant to merge without greater consensus and FC5 is very close to devel freeze. Not sure what expectations are for stability of python bindings API...

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.
#3 lore raw
Quoted 9 lines · Stephen Smalley
Quoted 8 lines · Ivan Gyurdiev

Okay, this patch is being the subject of controversy on IRC, so I wanted to continue discussion on-list.

It's an API change in the python bindings only, which converts out-bound arrays of objects (port, iface, boolean, etc..) to a PyList, which makes them easier to work with, and better integrated with the target language. Also, it fixes memory leak of the list structure (otherwise we have to expose free() to address that). It eliminates the need for get_by_idx functions, which are not really part of the libsemanage API.

Some problems w/ patch - it relies on some internal swig things - like the output variable being called result (swig provides $result, but that's in python, and I don't want to unpack it). Not sure if that's a problem, I'm not sure this t_output_helper business is part of the official API either. Also, swig is not very intelligent, and wants all the argument names to match (despite the docs saying otherwise).

Joshua doesn't like it..says semanage.i should be portable to other languages. However, I like better integration w/ python, so I think in that case maybe it makes sense to have several .i files. Also, I'm not sure the .i file is language portable right now - what will happen in a language that doesn't support an output vector, so adding things to result w/ t_output_helper doesn't necessarily make sense?

Quoted 9 lines
Quoted 1 line

Also, how do I implement a binding for set_roles()? I want to unpack a PyList into a char** array - requires understanding of python in the .i file.

Abstractly (while confessing total ignorance of swig), I would agree that we shouldn't cripple the python bindings for libsemanage just to allow a single interface file to be re-useable for other bindings. That said, I'm a little hesitant to merge without greater consensus and FC5 is very close to devel freeze. Not sure what expectations are for stability of python bindings API...

I don't disagree, my points were that 1) we don't want to totally eliminate the ability to build bindings for other languages and 2) we don't want to make maintenance of the bindings more difficult. If the python bindings are much better now (I'm no python developer so I don't know what pylists give us) then I don't have a problem merging it into a seperate .i file. I think we should reuse as much as possible so that it's easier to maintain if we ever want to support another binding.

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

#4 lore raw
In reply to Ivan Gyurdiev

Attached is a resync of this patch against current genhomedircon.

libsemanage/include/semanage/booleans_policy.h +1 -1
diff -Naurp --exclude-from excludes old/libsemanage/include/semanage/booleans_policy.h new/libsemanage/include/semanage/booleans_policy.h
@@ -30,6 +30,6 @@ extern int semanage_bool_iterate(
 extern int semanage_bool_list(
 	semanage_handle_t* handle,
 	semanage_bool_t*** records,
-	unsigned int* size);
+	unsigned int* count);
 
 #endif
libsemanage/src/pywrap-test.py +23 -51

177 lines not on this page · raw message

libsemanage/src/semanageswig.i +94 -34

171 lines not on this page · raw message

policycoreutils/scripts/genhomedircon +5 -6
diff -Naurp --exclude-from excludes old/policycoreutils/scripts/genhomedircon new/policycoreutils/scripts/genhomedircon
@@ -133,7 +133,7 @@ class selinuxConfig:
 		self.semanaged=semanage_is_managed(self.semanageHandle)
 		if self.semanaged:
 			semanage_connect(self.semanageHandle)
-			(status, self.ulist, self.usize) = semanage_user_list(self.semanageHandle)
+			(status, self.ulist) = semanage_user_list(self.semanageHandle)
 		self.type=type
 		self.selinuxdir=selinuxdir +"/"
 		self.contextdir="/contexts"
@@ -174,11 +174,11 @@ class selinuxConfig:
 		return ret
 
 	def get_default_prefix(self, name):
-		for idx in range(self.usize):
-			user = semanage_user_by_idx(self.ulist, idx)
+		for user in self.ulist:
 			if semanage_user_get_name(user) == name:
 				return semanage_user_get_prefix(user)
 		return name
+
 	def get_old_prefix(self, user):
 		rc=grep(self.selinuxdir+self.type+"/users/system.users", "^user %s" % user)
 		if rc == "":					    
@@ -219,10 +219,9 @@ class selinuxConfig:
 	def getUsers(self):
 		udict = {}
 		if self.semanaged:
-			(status, list, lsize) = semanage_seuser_list(self.semanageHandle)
-			for idx in range(lsize):
+			(status, list) = semanage_seuser_list(self.semanageHandle)
+			for seuser in list:
 				user=[]
-				seuser = semanage_seuser_by_idx(list, idx)
 				seusername=semanage_seuser_get_sename(seuser)
 				self.adduser(udict, semanage_seuser_get_name(seuser), seusername, self.get_default_prefix(seusername))
 				
policycoreutils/semanage/seobject.py +14 -21
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/seobject.py new/policycoreutils/semanage/seobject.py
@@ -288,12 +288,11 @@ class loginRecords(semanageRecords):
 		
 	def get_all(self):
 		ddict={}
-		(rc, self.ulist, self.usize) = semanage_seuser_list(self.sh)
+		(rc, self.ulist) = semanage_seuser_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list login mappings")
 
-		for idx in range(self.usize):
-			u = semanage_seuser_by_idx(self.ulist, idx)
+		for u in self.ulist:
 			name = semanage_seuser_get_name(u)
 			ddict[name]=(semanage_seuser_get_sename(u), semanage_seuser_get_mlsrange(u))
 		return ddict
@@ -447,12 +446,11 @@ class seluserRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.ulist, self.usize) = semanage_user_list(self.sh)
+		(rc, self.ulist) = semanage_user_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list SELinux users")
 
-		for idx in range(self.usize):
-			u = semanage_user_by_idx(self.ulist, idx)
+		for u in self.ulist:
 			name = semanage_user_get_name(u)
 			(rc, rlist, rlist_size) = semanage_user_get_roles(self.sh, u)
 			if rc < 0:
@@ -637,12 +635,11 @@ class portRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_port_list(self.sh)
+		(rc, self.plist) = semanage_port_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list ports")
 
-		for idx in range(self.psize):
-			port = semanage_port_by_idx(self.plist, idx)
+		for port in self.plist:
 			con = semanage_port_get_con(port)
 			ctype = semanage_context_get_type(con)
 			if ctype == "reserved_port_t":
@@ -657,12 +654,11 @@ class portRecords(semanageRecords):
 
 	def get_all_by_type(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_port_list(self.sh)
+		(rc, self.plist) = semanage_port_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list ports")
 
-		for idx in range(self.psize):
-			port = semanage_port_by_idx(self.plist, idx)
+		for port in self.plist:
 			con = semanage_port_get_con(port)
 			ctype = semanage_context_get_type(con)
 			if ctype == "reserved_port_t":
@@ -837,12 +833,11 @@ class interfaceRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_iface_list(self.sh)
+		(rc, self.ilist) = semanage_iface_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list interfaces")
 
-		for idx in range(self.psize):
-			interface = semanage_iface_by_idx(self.plist, idx)
+		for interface in self.ilist:
 			con = semanage_iface_get_ifcon(interface)
 			ddict[semanage_iface_get_name(interface)]=(semanage_context_get_user(con), semanage_context_get_role(con), semanage_context_get_type(con), semanage_context_get_mls(con))
 
@@ -1022,12 +1017,11 @@ class fcontextRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.plist, self.psize) = semanage_fcontext_list(self.sh)
+		(rc, self.flist) = semanage_fcontext_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list file contexts")
 
-		for idx in range(self.psize):
-			fcontext = semanage_fcontext_by_idx(self.plist, idx)
+		for fcontext in self.flist:
 			expr = semanage_fcontext_get_expr(fcontext)
 			ftype = semanage_fcontext_get_type(fcontext)
 			ftype_str = semanage_fcontext_get_type_str(ftype)
@@ -1124,12 +1118,11 @@ class booleanRecords(semanageRecords):
 
 	def get_all(self):
 		ddict={}
-		(rc, self.blist, self.bsize) = semanage_bool_list(self.sh)
+		(rc, self.blist) = semanage_bool_list(self.sh)
 		if rc < 0:
 			raise ValueError("Could not list booleans")
 
-		for idx in range(self.bsize):
-			boolean = semanage_bool_by_idx(self.blist, idx)
+		for boolean in self.blist:
 			name = semanage_bool_get_name(boolean)
 			value = semanage_bool_get_value(boolean)
 			ddict[name] = value
#5 lore raw

Move python bindings into semanageswig_python.i

Quoted 1 line · Ivan Gyurdiev

Attached is a resync of this patch against current genhomedircon.

Now move python stuff into semanageswig_python.i. Trim #include list to semanage/semanage.h, which is sufficient. Actually, I doubt that's needed at all, since swig seems to prototype all wrapped functions itself.

I define "python stuff" as any typemaps, which are overriding the normal SWIG-generated output with custom code - things that re-direct pointers to output, as well as list-to-array conversions. There should be no need to override swig in the language independent .i file. Also move the lone char_by_idx function. Other by_idx functions should be kept out, because they might not be needed in other languages. In fact, I should look at char_by_idx too, it's probably not needed.

Patch requires resync-ed pylist patch above, as well as the small free-leak patch I sent earlier.
It doesn't attempt to make the Makefile language independent - it just renames the current .i file being used (it's already hardcoded to use -python anyways).

libsemanage/src/Makefile +1 -1
diff -Naurp --exclude-from excludes old/libsemanage/src/Makefile new/libsemanage/src/Makefile
@@ -23,7 +23,7 @@ LIBVERSION = 1
 
 LIBA=libsemanage.a
 TARGET=libsemanage.so
-SWIGIF= semanageswig.i
+SWIGIF= semanageswig_python.i
 SWIGCOUT= semanageswig_wrap.c
 SWIGLOBJ:= $(patsubst %.c,%.lo,$(SWIGCOUT)) 
 SWIGSO=_semanage.so
libsemanage/src/semanageswig.i +1 -372

388 lines not on this page · raw message

libsemanage/src/semanageswig_python.i +366 -0

366 lines not on this page · raw message

#6 lore raw

Improve bindings, add PyList(String) for roles array

ChangeLog:

- Split out PyList building code and put it in a common function. In that function:
- audit failure in PyNew
- audit failure in PyAppend (used to be SetItem)
- audit failure in SWIG_NewPointerObj
- on failure, call the object destructor function on the entire list,
and return STATUS_ERR.

I'm not sure if that accomplishes much. I suspect the swig wrappers
have a million ways in which they can fail internally. Yet, I feel like it is wrong to not audit errors in code that I write, so this corrects that mistake. I also like the idea of the list building code being in a common function.

- Add more PyLists..... convert semanage_user_get_roles() to using PyList, instead of character arrays.
- Remove char_by_idx.
- fix dependency in seobject.py
- unlike other wrappers, this one also converts the string itself,
from char* to a python string
(see semanage2plist, which can be called in two ways)

- Use fewer SWIG internal conventions
- don't use the result variable - use the $result python variable,
which is documented. Use SWIG_As_int to get the integer out of it.
- do not use SWIGTYPE_...* where possible. Use special variables
that provide access to the descriptor without writing out the type.

Next:
- make the opposite conversion, and make set_roles() work properly
- try to get rid of usage of t_output_helper()

libsemanage/src/pywrap-test.py +4 -3
diff -Naurp --exclude-from excludes old/libsemanage/src/pywrap-test.py new/libsemanage/src/pywrap-test.py
@@ -178,12 +178,13 @@ class Tests:
 			print "   User mls range: ", semanage.semanage_user_get_mlsrange(user)
 			print "   User number of roles: ", semanage.semanage_user_get_num_roles(user)
 			print "   User roles: "
-			(status, rlist, rlist_size) = semanage.semanage_user_get_roles(sh, user)
+			(status, rlist) = semanage.semanage_user_get_roles(sh, user)
 			if status < 0:
 				raise Error("Could not get user roles")
+				
+			for role in rlist:
+				print "      ", role
 
-			for ridx in range (rlist_size):
-				print "      ", semanage.char_by_idx(rlist, ridx)
 			semanage.semanage_user_free(user)
 
 	def test_ports(self,sh):
libsemanage/src/semanageswig.i +0 -3
diff -Naurp --exclude-from excludes old/libsemanage/src/semanageswig.i new/libsemanage/src/semanageswig.i
@@ -20,9 +20,6 @@
 
 
 %module semanage
-%{
-	#include "semanage/semanage.h"
-%}
 
 /* pull in the headers */
 %include "../include/semanage/debug.h"
libsemanage/src/semanageswig_python.i +194 -105

455 lines not on this page · raw message

policycoreutils/semanage/seobject.py +2 -7
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/seobject.py new/policycoreutils/semanage/seobject.py
@@ -452,16 +452,11 @@ class seluserRecords(semanageRecords):
 
 		for u in self.ulist:
 			name = semanage_user_get_name(u)
-			(rc, rlist, rlist_size) = semanage_user_get_roles(self.sh, u)
+			(rc, rlist) = semanage_user_get_roles(self.sh, u)
 			if rc < 0:
 				raise ValueError("Could not list roles for user %s" % name)
 
-			roles = ""
-
-			if rlist_size:
-				roles += char_by_idx(rlist, 0)
-				for ridx in range (1,rlist_size):
-					roles += " " + char_by_idx(rlist, ridx)
+			roles = string.join(rlist, ' ');
 			ddict[semanage_user_get_name(u)] = (semanage_user_get_mlslevel(u), semanage_user_get_mlsrange(u), roles)
 
 		return ddict
#9 lore raw
In reply to Ivan Gyurdiev
Quoted 1 line · Ivan Gyurdiev

Attached is a resync of this patch against current genhomedircon.

Merged as of libsemanage 1.5.24 and policycoreutils 1.29.24.

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.
#8 lore raw

Re: Move python bindings into semanageswig_python.i

In reply to Ivan Gyurdiev
Quoted 14 lines · Ivan Gyurdiev
Quoted 1 line · Ivan Gyurdiev

Attached is a resync of this patch against current genhomedircon.

Now move python stuff into semanageswig_python.i. Trim #include list to semanage/semanage.h, which is sufficient. Actually, I doubt that's needed at all, since swig seems to prototype all wrapped functions itself.

I define "python stuff" as any typemaps, which are overriding the normal SWIG-generated output with custom code - things that re-direct pointers to output, as well as list-to-array conversions. There should be no need to override swig in the language independent .i file. Also move the lone char_by_idx function. Other by_idx functions should be kept out, because they might not be needed in other languages. In fact, I should look at char_by_idx too, it's probably not needed.

Quoted 5 lines

Patch requires resync-ed pylist patch above, as well as the small free-leak patch I sent earlier.
It doesn't attempt to make the Makefile language independent - it just renames the current .i file being used (it's already hardcoded to use -python anyways).

Merged as of libsemanage 1.5.24 as well.

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.
#7 lore raw

Re: Improve bindings, add PyList(String) for roles array

In reply to Ivan Gyurdiev
Quoted 24 lines · Ivan Gyurdiev

ChangeLog:

- Split out PyList building code and put it in a common function. In that function:
- audit failure in PyNew
- audit failure in PyAppend (used to be SetItem)
- audit failure in SWIG_NewPointerObj
- on failure, call the object destructor function on the entire list,
and return STATUS_ERR.

I'm not sure if that accomplishes much. I suspect the swig wrappers
have a million ways in which they can fail internally. Yet, I feel like it is wrong to not audit errors in code that I write, so this corrects that mistake. I also like the idea of the list building code being in a common function.

- Add more PyLists..... convert semanage_user_get_roles() to using PyList, instead of character arrays.
- Remove char_by_idx.
- fix dependency in seobject.py
- unlike other wrappers, this one also converts the string itself,
from char* to a python string
(see semanage2plist, which can be called in two ways)

Quoted 5 lines

- Use fewer SWIG internal conventions
- don't use the result variable - use the $result python variable,
which is documented. Use SWIG_As_int to get the integer out of it.
- do not use SWIGTYPE_...* where possible. Use special variables
that provide access to the descriptor without writing out the type.

Merged as of libsemanage 1.5.25 and policycoreutils 1.29.25.

Quoted 3 lines

Next:
- make the opposite conversion, and make set_roles() work properly
- try to get rid of usage of t_output_helper()

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.