This file is indexed.

/usr/sbin/semanage is in policycoreutils 2.1.0-3ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#! /usr/bin/python -E
# Copyright (C) 2005, 2006, 2007 Red Hat 
# see file 'COPYING' for use and warranty information
#
# semanage is a tool for managing SELinux configuration files
#
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of the GNU General Public License as
#    published by the Free Software Foundation; either version 2 of
#    the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     
#                                        02111-1307  USA
#
#  
import sys, getopt, re
import seobject
import selinux
PROGNAME="policycoreutils"

import gettext
gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
gettext.textdomain(PROGNAME)

try:
       gettext.install(PROGNAME,
                       localedir="/usr/share/locale",
                       unicode=False,
                       codeset = 'utf-8')
except IOError:
       import __builtin__
       __builtin__.__dict__['_'] = unicode

if __name__ == '__main__':

	def usage(message = ""):
               text = _("""
semanage [ -S store ] -i [ input_file | - ]

semanage {boolean|login|user|port|interface|node|fcontext} -{l|D} [-n]
semanage login -{a|d|m} [-sr] login_name | %groupname
semanage user -{a|d|m} [-LrRP] selinux_name
semanage port -{a|d|m} [-tr] [ -p proto ] port | port_range
semanage interface -{a|d|m} [-tr] interface_spec
semanage node -{a|d|m} [-tr] [ -p protocol ] [-M netmask] addr
semanage fcontext -{a|d|m} [-frst] file_spec
semanage boolean -{d|m} [--on|--off|-1|-0] -F boolean | boolean_file
semanage permissive -{d|a} type
semanage dontaudit [ on | off ]

Primary Options:

	-a, --add        Add a OBJECT record NAME
	-d, --delete     Delete a OBJECT record NAME
	-m, --modify     Modify a OBJECT record NAME
        -i, --input      Input multiple semange commands in a transaction 
	-l, --list       List the OBJECTS
	-C, --locallist  List OBJECTS local customizations
	-D, --deleteall  Remove all OBJECTS local customizations

	-h, --help       Display this message
	-n, --noheading  Do not print heading when listing OBJECTS
        -S, --store      Select and alternate SELinux store to manage

Object-specific Options (see above):

	-f, --ftype      File Type of OBJECT 
		"" (all files) 
		-- (regular file) 
		-d (directory) 
		-c (character device) 
		-b (block device) 
		-s (socket) 
		-l (symbolic link) 
		-p (named pipe) 

        -F, --file       Treat target as an input file for command, change multiple settings
	-p, --proto      Port protocol (tcp or udp) or internet protocol version of node (ipv4 or ipv6)
	-M, --mask       Netmask
	-P, --prefix     Prefix for home directory labeling
	-L, --level      Default SELinux Level (MLS/MCS Systems only)
	-R, --roles      SELinux Roles (ex: "sysadm_r staff_r")
	-s, --seuser     SELinux User Name
	-t, --type       SELinux Type for the object
	-r, --range      MLS/MCS Security Range (MLS/MCS Systems only)
""")
               raise ValueError("%s\n%s" % (text, message))
		
	def errorExit(error):
		sys.stderr.write("%s: " % sys.argv[0])
		sys.stderr.write("%s\n" % error)
		sys.stderr.flush()
		sys.exit(1)

	def get_options():
		valid_option={}
		valid_everyone=[ '-a', '--add', '-d', '--delete', '-m', '--modify', '-l', '--list', '-h', '--help', '-n', '--noheading', '-C', '--locallist', '-D', '--deleteall', '-S', '--store' ]
		valid_option["login"] = []
		valid_option["login"] += valid_everyone + [ '-s', '--seuser', '-r', '--range']
		valid_option["user"] = []
		valid_option["user"] += valid_everyone + [ '-L', '--level', '-r', '--range', '-R', '--roles', '-P', '--prefix' ] 
		valid_option["port"] = []
		valid_option["port"] += valid_everyone + [ '-t', '--type', '-r', '--range', '-p', '--proto' ]
		valid_option["interface"] = []
		valid_option["interface"] += valid_everyone + [ '-t', '--type', '-r', '--range']
		valid_option["node"] = []
		valid_option["node"] += valid_everyone + [ '-M', '--mask', '-t', '--type', '-r', '--range', '-p', '--protocol']
		valid_option["fcontext"] = []
		valid_option["fcontext"] += valid_everyone + [ '-f', '--ftype', '-s', '--seuser',  '-t', '--type', '-r', '--range'] 
		valid_option["dontaudit"] = [ '-S', '--store' ]
		valid_option["boolean"] = []
		valid_option["boolean"] += valid_everyone + [ '--on', "--off", "-1", "-0", "-F", "--file"] 
		valid_option["permissive"] = []
		valid_option["permissive"] += [ '-a', '--add', '-d', '--delete', '-l', '--list', '-h', '--help', '-n', '--noheading', '-D', '--deleteall' ]
		return valid_option

        def mkargv(line):
               dquote = "\""
               squote = "\'"
               l = line.split()
               ret = []
               i = 0
               while i < len(l):
                      cnt = len(re.findall(dquote, l[i]))
                      if cnt > 1:
                             ret.append(l[i].strip(dquote))
                             i = i + 1
                             continue
                      if cnt == 1:
                             quote = [ l[i].strip(dquote) ]
                             i = i + 1
                             
                             while i < len(l) and  dquote not in l[i]:
                                    quote.append(l[i])
                                    i = i + 1
                             quote.append(l[i].strip(dquote))
                             ret.append(" ".join(quote))
                             i = i + 1
                             continue

                      cnt = len(re.findall(squote, l[i]))
                      if cnt > 1:
                             ret.append(l[i].strip(squote))
                             i = i + 1
                             continue
                      if cnt == 1:
                             quote = [ l[i].strip(squote) ]
                             i = i + 1
                             while i < len(l) and  squote not in l[i]:
                                    quote.append(l[i])
                                    i = i + 1

                             quote.append(l[i].strip(squote))
                             ret.append(" ".join(quote))
                             i = i + 1
                             continue

                      ret.append(l[i])
                      i = i + 1

               return ret

        def process_args(argv):
		serange = ""
		port = ""
		proto = ""
		mask = ""
		selevel = ""
		setype = ""
		ftype = ""
		roles = ""
		seuser = ""
		prefix = "user"
		heading = True
		value = None
		add = False
		modify = False
		delete = False
		deleteall = False
		list = False
		locallist = False
		use_file = False
                store = ""
			
		object = argv[0]
		option_dict=get_options()
		if object not in option_dict.keys():
			usage(_("Invalid parameter %s not defined") % object)
			
		args = argv[1:]

		gopts, cmds = getopt.getopt(args,
					    '01adf:i:lhmnp:s:FCDR:L:r:t:P:S:M:',
					    ['add',
					     'delete',
					     'deleteall',
					     'ftype=',
					     'file',
					     'help',
                                             'input=',
					     'list', 
					     'modify',
					     'noheading',
					     'localist',
                                             'off', 
                                             'on', 
					     'proto=',
					     'seuser=',
					     'store=',
					     'range=',
					     'locallist=',
					     'level=',
					     'roles=',
					     'type=',
					     'prefix=',
                                             'mask='
					     ])
		for o, a in gopts:
			if o not in option_dict[object]:
				sys.stderr.write(_("%s not valid for %s objects\n") % ( o, object) );
				
		for o,a in gopts:
			if o == "-a" or o == "--add":
				if modify or delete:
                                       raise ValueError(_("%s bad option") % o)
				add = True
				
			if o == "-d"  or o == "--delete":
				if modify or add:
                                       raise ValueError(_("%s bad option") % o)
				delete = True
			if o == "-D"  or o == "--deleteall":
				if modify:
                                       raise ValueError(_("%s bad option") % o)
				deleteall = True
			if o == "-f"  or o == "--ftype":
				ftype=a

			if o == "-F"  or o == "--file":
				use_file = True

			if o == "-h" or o == "--help":
                               raise ValueError(_("%s bad option") % o)

			if o == "-n" or o == "--noheading":
				heading = False

			if o == "-C" or o == "--locallist":
				locallist = True

			if o == "-m"or o == "--modify":
				if delete or add:
                                       raise ValueError(_("%s bad option") % o)
				modify = True
				
			if o == "-S" or o == '--store':
				store = a

			if o == "-r" or o == '--range':
				serange = a

			if o == "-l" or o == "--list":
				list = True

			if o == "-L" or o == '--level':
				selevel = a

			if o == "-p" or o == '--proto':
				proto = a

			if o == "-P" or o == '--prefix':
				prefix = a

			if o == "-R" or o == '--roles':
				roles = roles + " " + a

			if o == "-s" or o == "--seuser":
				seuser = a

			if o == "-M" or o == '--mask':
				mask = a

			if o == "-t" or o == "--type":
				setype = a

                        if o == "--on" or o == "-1":
                               value = "on"
                        if o == "--off" or o == "-0":
                               value = "off"

		if object == "login":
			OBJECT = seobject.loginRecords(store)

		if object == "user":
			OBJECT = seobject.seluserRecords(store)

		if object == "port":
			OBJECT = seobject.portRecords(store)
		
		if object == "interface":
			OBJECT = seobject.interfaceRecords(store)

		if object == "node":
			OBJECT = seobject.nodeRecords(store)

		if object == "fcontext":
			OBJECT = seobject.fcontextRecords(store)
		
		if object == "boolean":
			OBJECT = seobject.booleanRecords(store)
		
		if object == "permissive":
			OBJECT = seobject.permissiveRecords(store)
		
		if list:
			if object == "boolean":
                               OBJECT.list(heading, locallist, use_file)
			else:
                               OBJECT.list(heading, locallist)
                        return
			
		if deleteall:
			OBJECT.deleteall()
                        return
			
		if len(cmds) != 1:
                       raise ValueError(_("%s bad option") % o)
                        
                target = cmds[0]


		if object == "dontaudit":
			OBJECT = seobject.dontauditClass(store)
                        OBJECT.toggle(target)
                        return
                              
		if add:
			if object == "login":
				OBJECT.add(target, seuser, serange)

			if object == "user":
				OBJECT.add(target, roles.split(), selevel, serange, prefix)

			if object == "port":
				OBJECT.add(target, proto, serange, setype)

			if object == "interface":
				OBJECT.add(target, serange, setype)

			if object == "node":
				OBJECT.add(target, mask, proto, serange, setype)

			if object == "fcontext":
				OBJECT.add(target, setype, ftype, serange, seuser)
			if object == "permissive":
				OBJECT.add(target)

                        return
			
		if modify:
			if object == "boolean":
                               OBJECT.modify(target, value, use_file)

			if object == "login":
				OBJECT.modify(target, seuser, serange)

			if object == "user":
				rlist = roles.split()
				OBJECT.modify(target, rlist, selevel, serange, prefix)

			if object == "port":
				OBJECT.modify(target, proto, serange, setype)

			if object == "interface":
				OBJECT.modify(target, serange, setype)

			if object == "node":
				OBJECT.modify(target, mask, proto, serange, setype)

			if object == "fcontext":
				OBJECT.modify(target, setype, ftype, serange, seuser)

                        return

		if delete:
			if object == "port":
				OBJECT.delete(target, proto)

			elif object == "fcontext":
				OBJECT.delete(target, ftype)

			elif object == "node":
				OBJECT.delete(target, mask, proto)

			else:
				OBJECT.delete(target)

                        return

                raise ValueError(_("Invalid command") % " ".join(argv))

	#
	# 
	#
	try:
               input = None
               store = ""

               if len(sys.argv) < 3:
                      usage(_("Requires 2 or more arguments"))
                
               gopts, cmds = getopt.getopt(sys.argv[1:],
                                           '01adf:i:lhmnp:s:FCDR:L:r:t:T:P:S:',
                                           ['add',
                                            'delete',
                                            'deleteall',
                                            'ftype=',
                                            'file',
                                            'help',
                                            'input=',
                                            'list', 
                                            'modify',
                                            'noheading',
                                            'localist',
                                            'off', 
                                            'on', 
                                            'proto=',
                                            'seuser=',
                                            'store=',
                                            'range=',
                                            'level=',
                                            'roles=',
                                            'type=',
                                            'prefix='
                                            ])
               for o, a in gopts:
                      if o == "-S" or o == '--store':
                             store = a
                      if o == "-i" or o == '--input':
                             input = a

               if input != None:
                      if input == "-":
                             fd = sys.stdin
                      else:
                             fd = open(input, 'r')
                      trans = seobject.semanageRecords(store)
                      trans.start()
                      for l in fd.readlines():
                             process_args(mkargv(l))
                      trans.finish()
               else:
                      process_args(sys.argv[1:])
			
	except getopt.error, error:
		usage(_("Options Error %s ") % error.msg)
	except ValueError, error:
		errorExit(error.args[0])
	except KeyError, error:
		errorExit(_("Invalid value %s") % error.args[0])
	except IOError, error:
		errorExit(error.args[1])