2009-03-06 12:25:46 +00:00
|
|
|
{pkgs, config, ...}:
|
2009-05-20 15:43:31 +00:00
|
|
|
|
2009-05-25 15:36:57 +00:00
|
|
|
with pkgs.lib;
|
|
|
|
|
2009-03-06 12:25:46 +00:00
|
|
|
let
|
2009-05-25 15:36:57 +00:00
|
|
|
|
2009-08-16 17:24:59 +00:00
|
|
|
inherit (config.security) wrapperDir;
|
|
|
|
|
2009-05-25 15:36:57 +00:00
|
|
|
setuidWrapper = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "setuid-wrapper";
|
|
|
|
buildCommand = ''
|
|
|
|
ensureDir $out/bin
|
2009-08-16 21:11:04 +00:00
|
|
|
gcc -Wall -O2 -DWRAPPER_DIR=\"${wrapperDir}\" \
|
|
|
|
${./setuid-wrapper.c} -o $out/bin/setuid-wrapper
|
2009-05-25 15:36:57 +00:00
|
|
|
strip -s $out/bin/setuid-wrapper
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-03-06 12:25:46 +00:00
|
|
|
in
|
2009-05-20 15:43:31 +00:00
|
|
|
|
2009-03-06 12:25:46 +00:00
|
|
|
{
|
2009-08-16 14:54:31 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
security.setuidPrograms = mkOption {
|
2009-08-16 21:11:04 +00:00
|
|
|
default = [];
|
2009-08-16 14:54:31 +00:00
|
|
|
description = ''
|
|
|
|
Only the programs from system path listed here will be made
|
|
|
|
setuid root (through a wrapper program).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
security.extraSetuidPrograms = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = ["fusermount"];
|
|
|
|
description = ''
|
|
|
|
This option lists additional programs that must be made setuid
|
2010-05-14 21:01:06 +00:00
|
|
|
root. Obsolete, use setuidPrograms instead.
|
2009-08-16 14:54:31 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
security.setuidOwners = mkOption {
|
|
|
|
default = [];
|
|
|
|
example =
|
|
|
|
[ { program = "sendmail";
|
|
|
|
owner = "nobody";
|
|
|
|
group = "postdrop";
|
|
|
|
setuid = false;
|
|
|
|
setgid = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
This option allows the ownership and permissions on the setuid
|
|
|
|
wrappers for specific programs to be overriden from the
|
|
|
|
default (setuid root, but not setgid root).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
security.wrapperDir = mkOption {
|
|
|
|
default = "/var/setuid-wrappers";
|
|
|
|
description = ''
|
|
|
|
This option defines the path to the setuid wrappers. It
|
|
|
|
should generally not be overriden.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = {
|
2009-08-16 21:11:04 +00:00
|
|
|
|
|
|
|
security.setuidPrograms =
|
2010-05-28 14:59:34 +00:00
|
|
|
[ "passwd" "chfn" "su" "crontab" "ping" "ping6"
|
2009-08-16 21:11:04 +00:00
|
|
|
"fusermount" "wodim" "cdrdao" "growisofs"
|
|
|
|
];
|
|
|
|
|
2009-08-16 14:54:31 +00:00
|
|
|
system.activationScripts.setuid =
|
|
|
|
let
|
2009-08-16 17:24:59 +00:00
|
|
|
setuidPrograms =
|
|
|
|
(map (x: { program = x; owner = "root"; group = "root"; setuid = true; })
|
|
|
|
(config.security.setuidPrograms ++
|
|
|
|
config.security.extraSetuidPrograms))
|
|
|
|
++ config.security.setuidOwners;
|
|
|
|
|
|
|
|
makeSetuidWrapper =
|
|
|
|
{ program
|
|
|
|
, source ? ""
|
|
|
|
, owner ? "nobody"
|
|
|
|
, group ? "nogroup"
|
|
|
|
, setuid ? false
|
|
|
|
, setgid ? false
|
|
|
|
, permissions ? "u+rx,g+rx,o+rx"
|
|
|
|
}:
|
|
|
|
|
2009-08-16 14:54:31 +00:00
|
|
|
''
|
2009-08-16 17:24:59 +00:00
|
|
|
source=${if source != "" then source else "$(PATH=$SETUID_PATH type -tP ${program})"}
|
|
|
|
if test -z "$source"; then
|
|
|
|
# If we can't find the program, fall back to the
|
|
|
|
# system profile.
|
|
|
|
source=/nix/var/nix/profiles/default/bin/${program}
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp ${setuidWrapper}/bin/setuid-wrapper ${wrapperDir}/${program}
|
|
|
|
echo -n "$source" > ${wrapperDir}/${program}.real
|
|
|
|
chmod 0000 ${wrapperDir}/${program} # to prevent races
|
|
|
|
chown ${owner}.${group} ${wrapperDir}/${program}
|
|
|
|
chmod "u${if setuid then "+" else "-"}s,g${if setgid then "+" else "-"}s,${permissions}" ${wrapperDir}/${program}
|
|
|
|
'';
|
2009-08-16 14:54:31 +00:00
|
|
|
|
|
|
|
in pkgs.stringsWithDeps.fullDepEntry
|
|
|
|
''
|
2009-05-25 15:36:57 +00:00
|
|
|
# Look in the system path and in the default profile for
|
2009-08-16 17:24:59 +00:00
|
|
|
# programs to be wrapped.
|
|
|
|
SETUID_PATH=${config.system.path}/bin:${config.system.path}/sbin
|
|
|
|
|
|
|
|
if test -d ${wrapperDir}; then rm -f ${wrapperDir}/*; fi # */
|
|
|
|
mkdir -p ${wrapperDir}
|
|
|
|
|
|
|
|
${concatMapStrings makeSetuidWrapper setuidPrograms}
|
2009-05-25 15:36:57 +00:00
|
|
|
'' [ "defaultPath" "users" ];
|
2009-08-16 14:54:31 +00:00
|
|
|
|
2009-05-20 15:43:31 +00:00
|
|
|
};
|
2009-08-16 14:54:31 +00:00
|
|
|
|
2009-03-06 12:25:46 +00:00
|
|
|
}
|