<br><br><div><span class="gmail_quote">On 4/19/07, <b class="gmail_sendername">Daniel J Walsh</b> <<a href="mailto:dwalsh@redhat.com">dwalsh@redhat.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Al Pacifico wrote:<br>> I (a greenhorn with selinux) am writing a policy for a daemon that<br>> streams music files over my home network to a music player client (a<br>> Slimdevices Squeezebox). My OS is FC5.<br>
><br>> The main daemon (/usr/sbin/slimserver) is a perl script that serves<br>> the music files and is started with an init script. My questions have<br>> to do with a secondary program (/usr/sbin/slimserver-scanner, also a
<br>> perl script) that scans the music on the server, reading mp3 tags and<br>> such, and generates a database of stored music that is stored in a<br>> MySQL database. /usr/sbin/slimserver-scanner is invoked by the
<br>> /usr/sbin/slimserver daemon and might be invoked by the user (although<br>> I can't recall ever doing so in several years of owning a Squeezebox).<br>><br>> I've been following the example posted by Dan Walsh in a blog at
<br>> <a href="http://danwalsh.livejournal.com/8707.html?thread=39171">http://danwalsh.livejournal.com/8707.html?thread=39171</a> which has been<br>> extremely helpful.<br>><br>> My (2) questions:<br>> 1. What is the appropriate file context for the scanner program?
<br>> system_u:object_r:sbin_t?<br>> system_u:object_r:slimserver_t?<br>> system_u:object_r:slimserver_exec_t?<br>><br>That depends on your security goals.  If you want the slimserver-scanner<br>to have the same privs as slimserver you would label it sbin_t and allow
<br>slimserver to corecmd_exec_sbin().  If you want to go with least privs,<br>you would create a new policy for slimserver-scanner<br>(slimserver_scanner_t with file context of slimserver_scanner_exec_t)<br>and then add a rule to slimserver_t to domtrans
<br>slimserver_scanner_domtrans(slimserver_t)</blockquote><div><br>After reviewing the source code to:<br>1) confirm that slimserver-scanner is intended to be run from the command line as well as by the slimserver daemon<br>
2) see if it logs to the slimserver log<br>3) determine if it might want to use the network<br>(to which all three answers were 'yes')<br>...I tried to use policygentool to create a policy for slimserver-scanner. However, I was stymied by an error.
<br><br>Here is what happened:<br>[root@joplin slimserver-scanner]# /usr/share/selinux/devel/policygentool slimserver-scanner /usr/sbin/slimserver-scanner<br><br><br>This tool generate three files for policy development, A Type Enforcement (te)
<br>file, a File Context (fc), and a Interface File(if).  Most of the policy rules<br>will be written in the te file.  Use the File Context file to associate file<br>paths with security context.  Use the interface rules to allow other protected
<br>domains to interact with the newly defined domains.<br><br>After generating these files use the /usr/share/selinux/devel/Makefile to<br>compile your policy package.  Then use the semodule tool to load it.<br><br># /usr/share/selinux/devel/policygentool myapp /usr/bin/myapp
<br># make -f /usr/share/selinux/devel/Makefile<br># semodule -l myapp.pp<br># restorecon -R -v /usr/bin/myapp "all files defined in myapp.fc"<br><br>Now you can turn on permissive mode, start your application and avc messages
<br>will be generated.  You can use audit2allow to help translate the avc messages<br>into policy.<br><br># setenforce 0<br># service myapp start<br># audit2allow -R -i /var/log/audit/audit.log<br><br>Return to continue:<br>
<br>If the module uses pidfiles, what is the pidfile called?<br><br>If the module uses logfiles, where are they stored?<br>/var/log/slimserver<br>If the module has var/lib files, where are they stored?<br><br>Does the module have a init script? [yN]
<br>N<br>Does the module use the network? [yN]<br>y<br>[root@joplin slimserver-scanner]# ls<br>slimserver-scanner.fc  slimserver-scanner.if  slimserver-scanner.te<br>[root@joplin slimserver-scanner]# make -f /usr/share/selinux/devel/Makefile
<br>Compiling targeted slimserver-scanner module<br>/usr/bin/checkmodule:  loading policy configuration from tmp/slimserver-scanner.tmp<br>slimserver-scanner.te:1:ERROR 'syntax error' at token 'slimserver-scanner' on line 59006:
<br>                module slimserver-scanner 1.0.0;<br>#line 1<br>/usr/bin/checkmodule:  error(s) encountered while parsing configuration<br>make: *** [tmp/slimserver-scanner.mod] Error 1<br><br>I thought I would display the line containing the error and associated context with the following:
<br>[root@joplin slimserver-scanner]# nl tmp/slimserver-scanner.tmp | sed -n '58990,59022p'<br> 50718  ##      Execute a domain transition to run slimserver-scanner.<br> 50719  ## </summary><br> 50720  ## <param name="domain">
<br> 50721  ## <summary><br> 50722  ##      Domain allowed to transition.<br> 50723  ## </summary><br> 50724  ## </param><br> 50725  #<br> 50726<br> 50727  #line 124172<br><br> 50728  #line 1 "slimserver-scanner.te
"<br><br> 50729  #line 1<br> 50730<br> 50731  #line 1<br> 50732                  module slimserver-scanner 1.0.0;<br> 50733  #line 1<br><br> 50734  #line 1<br> 50735                  require {<br> 50736  #line 1<br> 50737                          role system_r;
<br> 50738  #line 1<br> 50739<br> 50740  #line 1<br> 50741          class security { compute_av compute_create compute_member check_context load_policy compute_relabel compute_user setenforce setbool setsecparam setcheckreqprot };
<br> 50742  #line 1<br> 50743          class process { fork transition sigchld sigkill sigstop signull signal ptrace getsched setsched getsession getpgid setpgid getcap setcap share getattr setexec setfscreate noatsecure siginh setrlimit rlimitinh dyntransition setcurrent execmem execstack execheap setkeycreate };
<br> 50744  #line 1<br> 50745          class system { ipc_info syslog_read syslog_mod syslog_console }; 50746  #line 1<br> 50747          class capability { chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control };
<br><br>which does show the line 'module slimserver-scanner 1.0.0;', although the line numbering is inconsistent.<br><br>At first, I thought maybe policygentool inspected the context for the /usr/sbin/slimserver-scanner binary and that was the problem. Cursory examination of the source code did not suggest this. Now, I wonder if policygentool is only to be used for daemons. This wasn't stated in any comments. (BTW I'm using the 
selinux-policy-devel-2.3.7-2.fc5 package.)<br><br>Are there any thoughts regarding the nature of the error or suggestions for alternative tools for generating the policy?<br>-al<br></div><br></div>-- <br>Al Pacifico<br>Seattle, WA