Bug 1388331

Summary: semodule doesn't support input from stdin
Product: [Fedora] Fedora Reporter: Dominik 'Rathann' Mierzejewski <dominik>
Component: policycoreutilsAssignee: Petr Lautrbach <plautrba>
Status: CLOSED CANTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: rawhideCC: dwalsh, mgrepl, plautrba, pmoore, vmojzis
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-10-25 07:12:12 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Dominik 'Rathann' Mierzejewski 2016-10-25 07:00:00 UTC
Description of problem:
semodule -i doesn't support input from stdin

Version-Release number of selected component (if applicable):
policycoreutils-2.5-13.fc24.x86_64

How reproducible:
Always.

Steps to Reproduce:
# echo '(allow psad_t psad_var_log_t(file (read rename unlink write)))' | semodule -i
semodule: option requires an argument -- 'i'
usage:  semodule [options]... MODE [MODES]...
[...]
# echo '(allow psad_t psad_var_log_t(file (read rename unlink write)))' | semodule -i -
libsemanage.map_file: Unable to open -
 (No such file or directory).
libsemanage.semanage_direct_install_file: Unable to read file -
 (No such file or directory).
semodule:  Failed on -!

Expected results:
Successful policy import.

Additional info:
This would be useful in rpm scriptlets while avoiding temporary file creation. For now, I'm using this:

TMPDIR=$(%{_bindir}/mktemp -d)
cat >> $TMPDIR/psad-rpm.cil << __EOF__
(allow psad_t psad_var_log_t(file (read rename unlink write)))
__EOF__
%{_sbindir}/semodule -i $TMPDIR/psad-rpm.cil
rm $TMPDIR/psad-rpm.cil && rmdir $TMPDIR

Comment 1 Petr Lautrbach 2016-10-25 07:12:12 UTC
'semodule -i'  uses a filename as a module name and for detection if the module uses pp or cil language. In your case, 'semodule -i -' would create a module called '-' and wouldn't know what if it's cil or pp.

Comment 2 Dominik 'Rathann' Mierzejewski 2016-10-25 13:25:37 UTC
Well, how about adding command line options to set the module name and the "language" together with stdin input support?

Comment 3 Petr Lautrbach 2016-10-25 13:34:37 UTC
Please send your ideas and rationale to upstream mailing list at selinux.gov 

When it's accepted we can backport it to Fedora.