/usr/sbin
NameSizeModeActions
aa-load396800755editdlrm
aa-remove-unknown32250755editdlrm
aa-status400000755editdlrm
aa-teardown1370755editdlrm
accessdb149040755editdlrm
acpid539200755editdlrm
add-shell10530755editdlrm
addgnupghome30750755editdlrm
addgroup551910755editdlrm
adduser551910755editdlrm
agetty609920755editdlrm
apparmor_parser16298480755editdlrm
apparmor_status400000755editdlrm
applygnupgdefaults22170755editdlrm
argdist-bpfcc368620755editdlrm
arpd269600755editdlrm
arptables2244240755editdlrm
arptables-nft2244240755editdlrm
arptables-nft-restore2244240755editdlrm
arptables-nft-save2244240755editdlrm
arptables-restore2244240755editdlrm
arptables-save2244240755editdlrm
badblocks351440755editdlrm
bashreadline-bpfcc23800755editdlrm
bashreadline.bt6980755editdlrm
bcache-super-show146480755editdlrm
bindsnoop-bpfcc163460755editdlrm
biolatency-bpfcc113650755editdlrm
biolatency-kp.bt6640755editdlrm
biolatency.bt6810755editdlrm
biolatpcts-bpfcc102480755editdlrm
biopattern-bpfcc39570755editdlrm
biosdecode278560755editdlrm
biosnoop-bpfcc108330755editdlrm
biosnoop.bt11480755editdlrm
biostacks.bt9150755editdlrm
biotop-bpfcc95670755editdlrm
bitesize-bpfcc11660755editdlrm
bitesize.bt5670755editdlrm
blkdeactivate163510755editdlrm
blkdiscard229120755editdlrm
blkid557200755editdlrm
blkzone352000755editdlrm
blockdev352000755editdlrm
bpflist-bpfcc26010755editdlrm
bpftool16220755editdlrm
bridge1110960755editdlrm
btrfsdist-bpfcc66270755editdlrm
btrfsslower-bpfcc99850755editdlrm
cachestat-bpfcc65310755editdlrm
cachetop-bpfcc93670755editdlrm
cache_check14305680755editdlrm
cache_dump14305680755editdlrm
cache_metadata_size14305680755editdlrm
cache_repair14305680755editdlrm
cache_restore14305680755editdlrm
cache_writeback14305680755editdlrm
capable-bpfcc84770755editdlrm
capable.bt19260755editdlrm
capsh584560755editdlrm
cfdisk970080755editdlrm
cgdisk1704800755editdlrm
chcpu311040755editdlrm
chgpasswd597200755editdlrm
chmem352000755editdlrm
chpasswd557360755editdlrm
chronyd3062320755editdlrm
chroot394320755editdlrm
cobjnew-bpfcc530755editdlrm
compactsnoop-bpfcc113690755editdlrm
cpgr496080755editdlrm
cppw496080755editdlrm
cpudist-bpfcc70130755editdlrm
cpuunclaimed-bpfcc149380755editdlrm
cpuwalk.bt4970755editdlrm
criticalstat-bpfcc86070755editdlrm
cron600800755editdlrm
cryptdisks_start15440755editdlrm
cryptdisks_stop8440755editdlrm
cryptsetup2313200755editdlrm
ctrlaltdel147200755editdlrm
dbslower-bpfcc73910755editdlrm
dbstat-bpfcc37900755editdlrm
dcb824480755editdlrm
dcsnoop-bpfcc41260755editdlrm
dcsnoop.bt12610755editdlrm
dcstat-bpfcc38590755editdlrm
deadlock-bpfcc209430755editdlrm
debugfs2312880755editdlrm
delgroup189770755editdlrm
deluser189770755editdlrm
depmod1743280755editdlrm
devlink1544800755editdlrm
dhcpcd4048880755editdlrm
dirtop-bpfcc85680755editdlrm
dmeventd515920755editdlrm
dmidecode1384960755editdlrm
dmsetup1751600755editdlrm
dmstats1751600755editdlrm
dosfsck802640755editdlrm
dosfslabel393040755editdlrm
dpkg-preconfigure43560755editdlrm
dpkg-reconfigure45360755editdlrm
drsnoop-bpfcc68890755editdlrm
dumpe2fs351360755editdlrm
e2freefrag187440755editdlrm
e2fsck3730800755editdlrm
e2image433280755editdlrm
e2label1132160755editdlrm
e2mmpstatus351360755editdlrm
e2scrub72940755editdlrm
e2scrub_all53940755editdlrm
e2undo228400755editdlrm
e4crypt311040755editdlrm
e4defrag351280755editdlrm
ebtables2244240755editdlrm
ebtables-nft2244240755editdlrm
ebtables-nft-restore2244240755editdlrm
ebtables-nft-save2244240755editdlrm
ebtables-restore2244240755editdlrm
ebtables-save2244240755editdlrm
ebtables-translate2244240755editdlrm
era_check14305680755editdlrm
era_dump14305680755editdlrm
era_invalidate14305680755editdlrm
era_restore14305680755editdlrm
ethtool6673200755editdlrm
execsnoop-bpfcc100590755editdlrm
execsnoop.bt9280755editdlrm
exitsnoop-bpfcc96460755editdlrm
ext4dist-bpfcc66830755editdlrm
ext4slower-bpfcc99480755editdlrm
faillock228480755editdlrm
fatlabel393040755editdlrm
fdisk1171680755editdlrm
filefrag187600755editdlrm
filegone-bpfcc57760755editdlrm
filelife-bpfcc65280755editdlrm
fileslower-bpfcc73720755editdlrm
filetop-bpfcc64990755editdlrm
findfs147200755editdlrm
fixparts598800755editdlrm
fsadm245800755editdlrm
fsck434400755editdlrm
fsck.btrfs11850755editdlrm
fsck.cramfs311680755editdlrm
fsck.ext23730800755editdlrm
fsck.ext33730800755editdlrm
fsck.ext43730800755editdlrm
fsck.fat802640755editdlrm
fsck.minix557120755editdlrm
fsck.msdos802640755editdlrm
fsck.vfat802640755editdlrm
fsck.xfs25660755editdlrm
fsfreeze147200755editdlrm
fstab-decode146480755editdlrm
fstrim433920755editdlrm
funccount-bpfcc129810755editdlrm
funcinterval-bpfcc55900755editdlrm
funclatency-bpfcc115490755editdlrm
funcslower-bpfcc106300755editdlrm
gdisk2032480755editdlrm
genl1234720755editdlrm
getcap146480755editdlrm
gethostlatency-bpfcc39140755editdlrm
gethostlatency.bt12220755editdlrm
getpcaps146480755editdlrm
getty609920755editdlrm
groupadd728400755editdlrm
groupdel644240755editdlrm
groupmems597440755editdlrm
groupmod727440755editdlrm
grpck597200755editdlrm
grpconv513680755editdlrm
grpunconv513680755editdlrm
grub-bios-setup9815520755editdlrm
grub-install12258240755editdlrm
grub-macbless9691280755editdlrm
grub-mkconfig88400755editdlrm
grub-mkdevicemap723840755editdlrm
grub-probe9775760755editdlrm
grub-reboot48410755editdlrm
grub-set-default35560755editdlrm
halt15013040755editdlrm
hardirqs-bpfcc70190755editdlrm
hdparm1427760755editdlrm
iconvconfig352960755editdlrm
init1008160755editdlrm
inject-bpfcc164450755editdlrm
insmod1743280755editdlrm
install-sgmlcatalog45510755editdlrm
installkernel26590755editdlrm
integritysetup686720755editdlrm
invoke-rc.d165170755editdlrm
ip7729200755editdlrm
ip6tables2244240755editdlrm
ip6tables-apply70520755editdlrm
ip6tables-legacy951760755editdlrm
ip6tables-legacy-restore951760755editdlrm
ip6tables-legacy-save951760755editdlrm
ip6tables-nft2244240755editdlrm
ip6tables-nft-restore2244240755editdlrm
ip6tables-nft-save2244240755editdlrm
ip6tables-restore2244240755editdlrm
ip6tables-restore-translate2244240755editdlrm
ip6tables-save2244240755editdlrm
ip6tables-translate2244240755editdlrm
iptables2244240755editdlrm
iptables-apply70520755editdlrm
iptables-legacy951760755editdlrm
iptables-legacy-restore951760755editdlrm
iptables-legacy-save951760755editdlrm
iptables-nft2244240755editdlrm
iptables-nft-restore2244240755editdlrm
iptables-nft-save2244240755editdlrm
iptables-restore2244240755editdlrm
iptables-restore-translate2244240755editdlrm
iptables-save2244240755editdlrm
iptables-translate2244240755editdlrm
irqbalance602720755editdlrm
irqbalance-ui393040755editdlrm
iscsi-iname187440755editdlrm
iscsiadm3793200755editdlrm
iscsid2934320755editdlrm
iscsistart2810800755editdlrm
iscsi_discovery52930755editdlrm
isosize147200755editdlrm
iucode-tool556400755editdlrm
iucode_tool556400755editdlrm
javacalls-bpfcc550755editdlrm
javaflow-bpfcc540755editdlrm
javagc-bpfcc520755editdlrm
javaobjnew-bpfcc560755editdlrm
javastat-bpfcc540755editdlrm
javathreads-bpfcc570755editdlrm
kbdrate187520755editdlrm
killall5268560755editdlrm
killsnoop-bpfcc45540755editdlrm
killsnoop.bt8730755editdlrm
klockstat-bpfcc133560755editdlrm
kpartx431760755editdlrm
kvmexit-bpfcc114610755editdlrm
ldattach270080755editdlrm
ldconfig3870755editdlrm
ldconfig.real10512800755editdlrm
llcstat-bpfcc45840755editdlrm
loads.bt11270755editdlrm
locale-gen43160755editdlrm
logrotate965040755editdlrm
logsave144960755editdlrm
losetup763040755editdlrm
lsmod1743280755editdlrm
luksformat34010755editdlrm
lvchange31567120755editdlrm
lvconvert31567120755editdlrm
lvcreate31567120755editdlrm
lvdisplay31567120755editdlrm
lvextend31567120755editdlrm
lvm31567120755editdlrm
lvmconfig31567120755editdlrm
lvmdiskscan31567120755editdlrm
lvmdump103640755editdlrm
lvmpolld2416320755editdlrm
lvmsadc31567120755editdlrm
lvmsar31567120755editdlrm
lvreduce31567120755editdlrm
lvremove31567120755editdlrm
lvrename31567120755editdlrm
lvresize31567120755editdlrm
lvs31567120755editdlrm
lvscan31567120755editdlrm
lxc5890755editdlrm
lxd5890755editdlrm
make-bcache229120755editdlrm
mdadm6371440755editdlrm
mdflush-bpfcc22950755editdlrm
mdflush.bt7750755editdlrm
mdmon2650160755editdlrm
memleak-bpfcc212980755editdlrm
mkdosfs520480755editdlrm
mke2fs1337520755editdlrm
mkfs147200755editdlrm
mkfs.bfs229120755editdlrm
mkfs.btrfs5737520755editdlrm
mkfs.cramfs351440755editdlrm
mkfs.ext21337520755editdlrm
mkfs.ext31337520755editdlrm
mkfs.ext41337520755editdlrm
mkfs.fat520480755editdlrm
mkfs.minix434080755editdlrm
mkfs.msdos520480755editdlrm
mkfs.ntfs679760755editdlrm
mkfs.vfat520480755editdlrm
mkfs.xfs4495280755editdlrm
mkhomedir_helper228720755editdlrm
mkinitramfs157620755editdlrm
mklost+found146480755editdlrm
mkntfs679760755editdlrm
mkswap515920755editdlrm
ModemManager21655760755editdlrm
modinfo1743280755editdlrm
modprobe1743280755editdlrm
mount.fuse187360755editdlrm
mount.fuse3187360755editdlrm
mount.lowntfs-3g1218320755editdlrm
mount.ntfs1628240755editdlrm
mount.ntfs-3g1628240755editdlrm
mountsnoop-bpfcc149680755editdlrm
mpathpersist319600755editdlrm
multipath351280755editdlrm
multipathc187440755editdlrm
multipathd1458800755editdlrm
mysqld554679440755editdlrm
mysqld_qslower-bpfcc31250755editdlrm
naptime.bt10350755editdlrm
needrestart410920755editdlrm
netplan8020755editdlrm
netqtop-bpfcc57250755editdlrm
newusers890480755editdlrm
nfnl_osf187360755editdlrm
nfsdist-bpfcc50680755editdlrm
nfsslower-bpfcc139390755editdlrm
nft268560755editdlrm
nginx13141680755editdlrm
nodegc-bpfcc520755editdlrm
nodestat-bpfcc540755editdlrm
nologin146400755editdlrm
ntfsclone515920755editdlrm
ntfscp311040755editdlrm
ntfslabel229120755editdlrm
ntfsresize638880755editdlrm
ntfsundelete515920755editdlrm
offcputime-bpfcc137790755editdlrm
offwaketime-bpfcc156760755editdlrm
on_ac_power37880755editdlrm
oomkill-bpfcc20840755editdlrm
oomkill.bt11980755editdlrm
opensnoop-bpfcc145810755editdlrm
opensnoop.bt9530755editdlrm
overlayroot-chroot25100755editdlrm
ownership147920755editdlrm
pam-auth-update214650755editdlrm
pam_extrausers_chkpwd269442755editdlrm
pam_extrausers_update351360755editdlrm
pam_getenv28900755editdlrm
pam_namespace_helper4670755editdlrm
pam_timestamp_check146560755editdlrm
parted966640755editdlrm
partprobe147200755editdlrm
pdata_tools14305680755editdlrm
perlcalls-bpfcc550755editdlrm
perlflow-bpfcc540755editdlrm
perlstat-bpfcc540755editdlrm
php-fpm7.448033760755editdlrm
phpcalls-bpfcc540755editdlrm
phpdismod72780755editdlrm
phpenmod72780755editdlrm
phpflow-bpfcc530755editdlrm
phpquery63890755editdlrm
phpstat-bpfcc530755editdlrm
pidpersec-bpfcc11110755editdlrm
pidpersec.bt6280755editdlrm
pivot_root147200755editdlrm
plymouthd1500880755editdlrm
poweroff15013040755editdlrm
ppchcalls-bpfcc142240755editdlrm
profile-bpfcc147560755editdlrm
pvchange31567120755editdlrm
pvck31567120755editdlrm
pvcreate31567120755editdlrm
pvdisplay31567120755editdlrm
pvmove31567120755editdlrm
pvremove31567120755editdlrm
pvresize31567120755editdlrm
pvs31567120755editdlrm
pvscan31567120755editdlrm
pwck555920755editdlrm
pwconv472720755editdlrm
pwhistory_helper228480755editdlrm
pwunconv472720755editdlrm
pythoncalls-bpfcc570755editdlrm
pythonflow-bpfcc560755editdlrm
pythongc-bpfcc540755editdlrm
pythonstat-bpfcc560755editdlrm
rdmaucma-bpfcc50730755editdlrm
readahead-bpfcc66940755editdlrm
readprofile229440755editdlrm
reboot15013040755editdlrm
remove-shell11110755editdlrm
reset-trace-bpfcc34980755editdlrm
resize2fs719920755editdlrm
resolvconf1624800755editdlrm
rmmod1743280755editdlrm
rmt560240755editdlrm
rmt-tar560240755editdlrm
rsyslogd7901920755editdlrm
rtacct289920755editdlrm
rtcwake352000755editdlrm
rtmon1193120755editdlrm
rubycalls-bpfcc550755editdlrm
rubyflow-bpfcc540755editdlrm
rubygc-bpfcc520755editdlrm
rubyobjnew-bpfcc560755editdlrm
rubystat-bpfcc540755editdlrm
runlevel15013040755editdlrm
runqlat-bpfcc95260755editdlrm
runqlat.bt7880755editdlrm
runqlen-bpfcc82480755editdlrm
runqlen.bt10370755editdlrm
runqslower-bpfcc92250755editdlrm
runuser556800755editdlrm
service91040755editdlrm
setcap146480755editdlrm
setuids.bt17990755editdlrm
setvesablank147120755editdlrm
setvtrgb147760755editdlrm
sfdisk1089280755editdlrm
sgdisk1827680755editdlrm
shadowconfig22730755editdlrm
shmsnoop-bpfcc79850755editdlrm
shutdown15013040755editdlrm
slabratetop-bpfcc65370755editdlrm
sofdsnoop-bpfcc82550755editdlrm
softirqs-bpfcc57230755editdlrm
solisten-bpfcc61030755editdlrm
sshd9214160755editdlrm
ssllatency.bt21330755editdlrm
sslsniff-bpfcc140130755editdlrm
sslsnoop.bt20410755editdlrm
stackcount-bpfcc166550755editdlrm
start-stop-daemon486320755editdlrm
statsnoop-bpfcc50410755editdlrm
statsnoop.bt12940755editdlrm
sudo_logsrvd2544640755editdlrm
sudo_sendlog1348320755editdlrm
sulogin433920755editdlrm
swapin.bt6000755editdlrm
swaplabel188160755editdlrm
swapoff229120755editdlrm
swapon433920755editdlrm
switch_root229120755editdlrm
syncsnoop-bpfcc13000755editdlrm
syncsnoop.bt8390755editdlrm
syscount-bpfcc87710755editdlrm
syscount.bt8720755editdlrm
sysctl311120755editdlrm
tarcat9360755editdlrm
tc6452000755editdlrm
tclcalls-bpfcc540755editdlrm
tclflow-bpfcc530755editdlrm
tclobjnew-bpfcc550755editdlrm
tclstat-bpfcc530755editdlrm
tcpaccept-bpfcc92200755editdlrm
tcpaccept.bt17560755editdlrm
tcpcong-bpfcc205910755editdlrm
tcpconnect-bpfcc189020755editdlrm
tcpconnect.bt16150755editdlrm
tcpconnlat-bpfcc92850755editdlrm
tcpdrop-bpfcc76160755editdlrm
tcpdrop.bt24690755editdlrm
tcplife-bpfcc169490755editdlrm
tcplife.bt27850755editdlrm
tcpretrans-bpfcc140980755editdlrm
tcpretrans.bt21200755editdlrm
tcprtt-bpfcc89130755editdlrm
tcpstates-bpfcc140640755editdlrm
tcpsubnet-bpfcc78140755editdlrm
tcpsynbl-bpfcc21750755editdlrm
tcpsynbl.bt9620755editdlrm
tcptop-bpfcc129430755editdlrm
tcptracer-bpfcc181300755editdlrm
telinit15013040755editdlrm
thin_check14305680755editdlrm
thin_delta14305680755editdlrm
thin_dump14305680755editdlrm
thin_ls14305680755editdlrm
thin_metadata_size14305680755editdlrm
thin_repair14305680755editdlrm
thin_restore14305680755editdlrm
thin_rmap14305680755editdlrm
thin_trim14305680755editdlrm
threadsnoop-bpfcc18580755editdlrm
threadsnoop.bt7120755editdlrm
tipc926880755editdlrm
tplist-bpfcc41570755editdlrm
trace-bpfcc438920755editdlrm
ttysnoop-bpfcc76940755editdlrm
tune2fs1132160755editdlrm
ucalls119700755editdlrm
uflow81150755editdlrm
ufw49590755editdlrm
ugc78230755editdlrm
umount.udisks2146400755editdlrm
undump.bt7890755editdlrm
unix_chkpwd310402755editdlrm
unix_update351360755editdlrm
uobjnew61810755editdlrm
update-ca-certificates54460755editdlrm
update-catalog93930755editdlrm
update-grub640755editdlrm
update-grub-gfxpayload3010755editdlrm
update-grub2640755editdlrm
update-ieee-data34920755editdlrm
update-info-dir17000755editdlrm
update-initramfs69080755editdlrm
update-locale30570755editdlrm
update-passwd353920755editdlrm
update-pciids17780755editdlrm
update-rc.d181470755editdlrm
update-secureboot-policy76050755editdlrm
update-shells39840755editdlrm
update-xmlcatalog172840755editdlrm
upgrade-from-grub-legacy15960755editdlrm
usb_modeswitch610960755editdlrm
usb_modeswitch_dispatcher274180755editdlrm
useradd1432320755editdlrm
userdel931920755editdlrm
usermod1307120755editdlrm
ustat124120755editdlrm
uthreads41000755editdlrm
uuidd316240755editdlrm
validlocale17730755editdlrm
vcstime146400755editdlrm
vdpa353920755editdlrm
veritysetup449920755editdlrm
vfscount-bpfcc13900755editdlrm
vfscount.bt5150755editdlrm
vfsstat-bpfcc41590755editdlrm
vfsstat.bt7210755editdlrm
vgcfgbackup31567120755editdlrm
vgcfgrestore31567120755editdlrm
vgchange31567120755editdlrm
vgck31567120755editdlrm
vgconvert31567120755editdlrm
vgcreate31567120755editdlrm
vgdisplay31567120755editdlrm
vgexport31567120755editdlrm
vgextend31567120755editdlrm
vgimport31567120755editdlrm
vgimportclone31567120755editdlrm
vgmerge31567120755editdlrm
vgmknodes31567120755editdlrm
vgreduce31567120755editdlrm
vgremove31567120755editdlrm
vgrename31567120755editdlrm
vgs31567120755editdlrm
vgscan31567120755editdlrm
vgsplit31567120755editdlrm
vigr621440755editdlrm
vipw621440755editdlrm
virtiostat-bpfcc89000755editdlrm
visudo2587760755editdlrm
vpddecode149280755editdlrm
wakeuptime-bpfcc82910755editdlrm
wipefs392960755editdlrm
writeback.bt16990755editdlrm
xfsdist-bpfcc47230755editdlrm
xfsdist.bt9720755editdlrm
xfsslower-bpfcc79640755editdlrm
xfs_admin21740755editdlrm
xfs_bmap6950755editdlrm
xfs_copy926080755editdlrm
xfs_db7050880755editdlrm
xfs_estimate145040755editdlrm
xfs_freeze8000755editdlrm
xfs_fsr431920755editdlrm
xfs_growfs391520755editdlrm
xfs_info12940755editdlrm
xfs_io2085360755editdlrm
xfs_logprint801440755editdlrm
xfs_mdrestore350480755editdlrm
xfs_metadump8160755editdlrm
xfs_mkfile10400755editdlrm
xfs_ncheck6850755editdlrm
xfs_quota923280755editdlrm
xfs_repair6587600755editdlrm
xfs_rtcp185840755editdlrm
xfs_scrub1088160755editdlrm
xfs_scrub_all78410755editdlrm
xfs_spaceman433200755editdlrm
xtables-legacy-multi951760755editdlrm
xtables-monitor2244240755editdlrm
xtables-nft-multi2244240755editdlrm
zerofree144880755editdlrm
zfsdist-bpfcc54270755editdlrm
zfsslower-bpfcc86570755editdlrm
zic679840755editdlrm
zramctl558240755editdlrm
Edit: /usr/sbin/adduser (55191B)
#! /usr/bin/perl # Copyright (C) 2000-2004 Roland Bauerschmidt # 2005-2023 Marc Haber # 2022 Benjamin Drung # 2023 Guillem Jover # 2021-2022 Jason Franklin # 2022 Matt Barry # 2016-2017 Afif Elghraoui # 2016 Dr. Helge Kreutzmann # 2005-2009 Joerg Hoh # 2006-2011 Stephen Gran # # Original adduser: # Copyright (C) 1997-1999 Guy Maor # # Copyright (C) 1995 Ted Hajek # Ian A. Murdock # # The general scheme of this program was adapted from the original # Debian "adduser" program by Ian A. Murdock . # # License: GPL-2+ use 5.32.0; use strict; use warnings; use Getopt::Long; use Debian::AdduserCommon 3.136; use Debian::AdduserLogging 3.136; use Debian::AdduserRetvalues 3.136; BEGIN { if ( Debian::AdduserCommon->VERSION != version->declare('3.136') || Debian::AdduserLogging->VERSION != version->declare('3.136') || Debian::AdduserRetvalues->VERSION != version->declare('3.136') ) { die "wrong module version in adduser, check your packaging or path"; } } my $version = "3.137ubuntu1"; BEGIN { local $ENV{PERL_DL_NONLAZY}=1; # we need to disable perlcritic here since this construct # needs experession form eval, see perl cookbook 12.2.3 ## no critic eval " require POSIX; import POSIX qw(setlocale); "; ## use critic if ($@) { *setlocale = sub { return 1 }; } else { setlocale( &POSIX::LC_MESSAGES, "" ); } ## no critic eval " require I18N::Langinfo; import I18N::Langinfo qw(langinfo YESEXPR NOEXPR); "; ## use critic if ($@) { *langinfo = sub { return shift; }; *YESEXPR = sub { "^[yY]" }; *NOEXPR = sub { "^[nN]" }; } } my $yesexpr = langinfo(YESEXPR()); my %config; # configuration hash my $nogroup_id = getgrnam("nogroup") || 65534; $0 =~ s+.*/++; our $verbose = 1; # should we be verbose? my $name_check_level = 0; # should we allow bad names? our $stderrmsglevel = "warn"; our $stdoutmsglevel = "info"; our $logmsglevel = "info"; my $allow_badname = 0; # should we allow bad names? my $ask_passwd = 1; # ask for a passwd? my $disabled_login = 0; # leave the new account disabled? our @configfiles; our @defaults = undef; our $encrypt_home = undef; our $found_group_opt = undef; our $found_sys_opt = undef; our $ingroup_name = undef; our $new_firstgid = undef; our $new_firstuid = undef; our $new_comment = undef; our $gid_option = undef; our $primary_gid = undef; our $new_lastgid = undef; our $new_lastuid = undef; our $new_uid = undef; our $no_create_home = undef; our $special_home = undef; our $special_shell = undef; our $use_extrausers = 0; our $add_extra_groups; our $add_extra_groups_old; # Global variables we need later my $existing_user = undef; my $existing_group = undef; my $new_name = undef; my $make_group_also = 0; my $home_dir = undef; my $undohome = undef; my $undouser = undef; my $undogroup = undef; my $shell = undef; my $first_uid = undef; my $last_uid = undef; my $first_gid = undef; my $last_gid = undef; my $dir_mode = undef; my $perm = undef; my %uid_pool; my %gid_pool; our @names; GetOptions( 'add-extra-groups' => \$add_extra_groups, 'add_extra_groups' => \$add_extra_groups_old, 'allow-all-names' => sub { $name_check_level = 2 }, 'allow-badname' => sub { $name_check_level = 1 unless $name_check_level }, 'allow-bad-names' => sub { $name_check_level = 1 unless $name_check_level }, 'comment=s' => \$new_comment, 'conf|c=s' => \@configfiles, 'debug' => sub { $verbose = 2 }, 'stdoutmsglevel=s' => \$stdoutmsglevel, 'stderrmsglevel=s' => \$stderrmsglevel, 'logmsglevel=s' => \$logmsglevel, 'disabled-login' => sub { $disabled_login = 1; $ask_passwd = 0 }, 'disabled-password' => sub { $ask_passwd = 0 }, 'encrypt-home' => \$encrypt_home, 'extrausers' => \$use_extrausers, 'firstgid=i' => \$new_firstgid, 'firstuid=i' => \$new_firstuid, 'force-badname' => sub { $name_check_level = 1 unless $name_check_level }, 'gecos=s' => \$new_comment, 'gid=i' => \$gid_option, 'group' => \$found_group_opt, 'help|h' => sub { &usage; exit }, 'home=s' => \$special_home, 'ingroup=s' => \$ingroup_name, 'lastgid=i' => \$new_lastgid, 'lastuid=i' => \$new_lastuid, 'no-create-home' => \$no_create_home, 'quiet|q' => sub { $verbose = 0 }, 'shell=s' => \$special_shell, 'system' => \$found_sys_opt, 'uid=i' => \$new_uid, 'verbose' => sub { $verbose = 1 }, 'version|v' => sub { &version; exit }, ) or &usage_error; if(!@configfiles) { @defaults = ("/etc/adduser.conf"); } else { @defaults = (@configfiles); } # preseed configuration data and then read the config file preseed_config(\@defaults,\%config); # everyone can issue "--help" and "--version", but only root can go on if( $> != 0) { log_fatal( mtx("Only root may add a user or group to the system.") ); exit( RET_ROOT_NEEDED ); } # TODO: Handle configuration file input, allow bare input there. if( $verbose == 0 ) { set_msglevel( $stderrmsglevel, "warn", $logmsglevel ); } elsif( $verbose == 1 ) { set_msglevel( $stderrmsglevel, "info", $logmsglevel ); } elsif( $verbose == 2 ) { set_msglevel( $stderrmsglevel, "debug", $logmsglevel ); } else { set_msglevel( $stderrmsglevel, $stdoutmsglevel, $logmsglevel ); } # detect the right mode my $action = $0 eq "addgroup" ? "addgroup" : "adduser"; if (defined($found_sys_opt)) { $action = "addsysuser" if ($action eq "adduser"); $action = "addsysgroup" if ($action eq "addgroup"); } # explicitly set PATH, because super (1) cleans up the path and makes adduser unusable; # this is also a good idea for sudo (which doesn't clean up) $ENV{"PATH"}="/bin:/usr/bin:/sbin:/usr/sbin"; $ENV{"IFS"}=" \t\n"; ############################ # checks related to @names # ############################ while (defined(my $arg = shift(@ARGV))) { push (@names, $arg); } if ( (! defined $names[0]) || length($names[0]) == 0 || @names > 2) { log_fatal( mtx("Only one or two names allowed.") ); exit( RET_INVALID_CALL ); } if (@names == 2) { # must be addusertogroup if ($action eq "addsysuser" || $found_group_opt) { log_fatal( mtx("Specify only one name in this mode.") ); exit( RET_INVALID_CALL ); } if ($action eq "addgroup" or $action eq "addsysgroup") { log_fatal( mtx("addgroup with two arguments is an unspecified operation.") ); exit( RET_INVALID_CALL ); } $action = "addusertogroup"; $existing_user = shift (@names); $existing_group = shift (@names); } else { # 1 parameter, must be adduser $new_name = shift (@names); } ################################### # check for consistent parameters # ################################### if (!defined $add_extra_groups) { if( defined $add_extra_groups_old ) { $add_extra_groups = $add_extra_groups_old; } else { $add_extra_groups = 0; } } if ($action ne "addgroup" && defined($found_group_opt) +defined($ingroup_name) +defined($gid_option) > 1 ) { log_fatal( mtx("The --group, --ingroup, and --gid options are mutually exclusive.") ); exit( RET_EXCLUSIVE_PARAMETERS ); } if ((defined($special_home)) && ($special_home !~ m+^/+ )) { log_fatal( mtx("The home dir must be an absolute path.") ); exit( RET_INVALID_HOME_DIRECTORY ); } if (defined($special_home)) { if (!defined($no_create_home) && -d $special_home) { log_info( mtx("The home dir %s you specified already exists.\n"), $special_home ); } if (defined($no_create_home) && ! -d $special_home) { log_info( mtx("The home dir %s you specified can't be accessed: %s\n"), $special_home, $! ); } } if ($found_group_opt) { if ($action eq "addsysuser") { $make_group_also = 1; } elsif ($found_sys_opt) { $action = "addsysgroup"; } else { $action = "addgroup"; } } my $ecryptfs_setup_private; if (defined($encrypt_home)) { $ecryptfs_setup_private = &which('ecryptfs-setup-private'); } # TODO: map this to log levels $ENV{"VERBOSE"} = $verbose; $ENV{"DEBUG"} = $verbose; # preseed_config was moved from here # read the uid and gid pool if ($config{"uid_pool"}) { read_pool ($config{"uid_pool"}, "uid", \%uid_pool); } if ($config{"gid_pool"}) { read_pool ($config{"gid_pool"}, "gid", \%gid_pool); } &checkname($new_name) if defined $new_name; $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'handler'; ##### # OK, we've processed the arguments. $action equals one of the following, # and the appropriate variables have been set: # # $action = "adduser" # $new_name - the name of the new user. # $ingroup_name | $gid_option - the group to add the user to # $special_home, $new_uid, $new_comment - optional overrides # $action = "addgroup" # $new_name - the name of the new group # $gid_option - optional override # $action = "addsysgroup" # $new_name - the name of the new group # $gid_option - optional override # $action = "addsysuser" # $new_name - the name of the new user # $make_group_also | $ingroup_name | $gid_option | 0 - which group # $special_home, $new_uid, $new_comment - optional overrides # $action = "addusertogroup" # $existing_user - the user to be added # $existing_group - the group to add her to ##### ################# ## addsysgroup ## ################# if ($action eq "addsysgroup") { acquire_lock(); # Check if requested group already exists and we can exit safely my $ret = existing_group_ok($new_name, $gid_option); if ($ret == 3) { log_info( mtx("The group `%s' already exists as a system group. Exiting."), $new_name ); exit( RET_OK ); } if ($ret == 1) { log_err( mtx("The group `%s' already exists and is not a system group. Exiting."), $new_name ); exit( RET_WRONG_OBJECT_PROPERTIES ); } if ($ret == 2) { log_err( mtx("The group `%s' already exists, but has a different GID. Exiting."), $new_name ); exit( RET_WRONG_OBJECT_PROPERTIES ); } if (defined($gid_option) && defined(getgrgid($gid_option))) { log_fatal( mtx("The GID `%s' is already in use."), $gid_option ); exit( RET_ID_IN_USE ); } if (!defined($gid_option)) { $first_gid = $new_firstgid || $config{"first_system_gid"}; $last_gid = $new_lastgid || $config{"last_system_gid"}; $gid_option = &first_avail_gid($first_gid, $last_gid, $gid_pool{$new_name}{'id'}); if ($gid_option == -1) { log_warn( mtx("No GID is available in the range %d-%d (FIRST_SYS_GID - LAST_SYS_GID)."), $first_gid, $last_gid ); log_err( mtx("The group `%s' was not created."), $new_name ); exit( RET_NO_ID_IN_RANGE ); } } log_info( mtx("Adding group `%s' (GID %d) ..."), $new_name, $gid_option); my $groupadd = &which('groupadd'); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($groupadd, '--extrausers', '-g', $gid_option, $new_name); } else { &systemcall($groupadd, '-g', $gid_option, $new_name); } release_lock(0); exit( RET_OK ); } ############## ## addgroup ## ############## if ($action eq "addgroup") { acquire_lock(); if (defined getgrnam($new_name)) { log_fatal( mtx("The group `%s' already exists."), $new_name); exit( RET_OBJECT_EXISTS ); } if (defined($gid_option) && defined(getgrgid($gid_option))) { log_fatal( mtx("The GID `%s' is already in use."), $gid_option ); exit( RET_ID_IN_USE ); } if (!defined($gid_option)) { $first_gid = $new_firstgid || $config{"first_gid"}; $last_gid = $new_lastgid || $config{"last_gid"}; log_debug( "Searching for gid with first_gid=%s, last_gid=%s, new_name=%s, gid_pool=%s", $first_gid, $last_gid, $new_name, $gid_pool{$new_name}{'id'} ); $gid_option = &first_avail_gid($first_gid, $last_gid, $gid_pool{$new_name}{'id'}); if ($gid_option == -1) { log_warn( mtx("No GID is available in the range %d-%d (FIRST_GID - LAST_GID)."), $first_gid, $last_gid ); log_fatal( mtx("The group `%s' was not created."), $new_name ); exit( RET_NO_ID_IN_RANGE ); } } log_info( mtx("Adding group `%s' (GID %d) ..."), $new_name, $gid_option); my $groupadd = &which('groupadd'); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($groupadd, '--extrausers', '-g', $gid_option, $new_name); } else { &systemcall($groupadd, '-g', $gid_option, $new_name); } release_lock(0); exit( RET_OK ); } #################### ## addusertogroup ## #################### if ($action eq 'addusertogroup') { if (!defined getpwnam($existing_user)) { log_fatal( mtx("The user `%s' does not exist."), $existing_user ); exit( RET_OBJECT_DOES_NOT_EXIST ); } if (!defined getgrnam($existing_group)) { log_fatal( mtx("The group `%s' does not exist."), $existing_group ); exit( RET_OBJECT_DOES_NOT_EXIST ); } if (&user_is_member($existing_user, $existing_group)) { log_info( mtx("The user `%s' is already a member of `%s'."), $existing_user, $existing_group ); exit( RET_OK ); } log_info( mtx("Adding user `%s' to group `%s' ..."), $existing_user, $existing_group ); acquire_lock(); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall('/usr/sbin/usermod', '--extrausers', '-a', '-G', $existing_group, $existing_user); } else { &systemcall('/usr/sbin/usermod', '-a', '-G', $existing_group, $existing_user); } release_lock(); exit( RET_OK ); } ################ ## addsysuser ## ################ if ($action eq "addsysuser") { acquire_lock(); if (existing_user_ok($new_name, $new_uid) == 1) { # a user with this name already exists; it's a problem when it's not a system user my $tmp_u = getpwnam($new_name); if (($tmp_u >= $config{"first_system_uid"}) and ($tmp_u <= $config{"last_system_uid"})) { log_info( mtx("The system user `%s' already exists. Exiting.\n"), $new_name ); exit( RET_OK ); } log_fatal( mtx("The user `%s' already exists, but is not a system user. Exiting."), $new_name ); exit( RET_WRONG_OBJECT_PROPERTIES ); } if (existing_user_ok($new_name, $new_uid) == 2) { log_fatal( mtx("The user `%s' already exists with a different UID. Exiting."), $new_name ); exit( RET_WRONG_OBJECT_PROPERTIES ); } if (!$ingroup_name && !defined($gid_option) && !$make_group_also) { $gid_option = $nogroup_id; } check_user_group(1); if (!defined($new_uid) && $make_group_also) { $new_uid = &first_avail_uid($new_firstuid || $config{"first_system_uid"}, $new_lastuid || $config{"last_system_uid"}, $uid_pool{$new_name}{'id'}); if ($new_uid == -1) { log_warn( mtx("No UID/GID pair is available in the range %d-%d (FIRST_SYS_UID - LAST_SYS_UID)."), $config{"first_system_uid"}, $config{"last_system_uid"} ); log_fatal( mtx("The user `%s' was not created."), $new_name ); exit( RET_NO_ID_IN_RANGE ); } $gid_option = &first_avail_gid($new_firstgid || $config{"first_system_gid"}, $new_lastgid || $config{"last_system_gid"}, $gid_pool{$new_name}{'id'}); $ingroup_name = $new_name; } elsif (!defined($new_uid) && !$make_group_also) { $new_uid = &first_avail_uid($new_firstuid || $config{"first_system_uid"}, $new_lastuid || $config{"last_system_uid"}, $uid_pool{$new_name}{'id'}); if ($new_uid == -1) { log_warn( mtx("No UID is available in the range %d-%d (FIRST_SYS_UID - LAST_SYS_UID)."), $config{"first_system_uid"}, $config{"last_system_uid"} ); log_fatal( mtx("The user `%s' was not created."), $new_name); exit( RET_NO_ID_IN_RANGE ); } if (defined($gid_option)) { $ingroup_name = getgrgid($gid_option); } elsif ($ingroup_name) { $gid_option = getgrnam($ingroup_name); } else { log_fatal( mtx("Neither ingroup option nor gid given.") ); exit( RET_NO_PRIMARY_GROUP ); } } else { if (defined($gid_option)) { $ingroup_name = getgrgid($gid_option); } elsif ($ingroup_name) { $gid_option = getgrnam($ingroup_name); } elsif ($make_group_also) { $gid_option=$new_uid; $ingroup_name=$new_name; } else { log_fatal( mtx("Neither ingroup option nor gid given and make_group_also unset.") ); exit( RET_NO_PRIMARY_GROUP ); } } log_info( mtx("Adding system user `%s' (UID %d) ..."), $new_name, $new_uid ); # if we reach this point, and the group does already exist, we can use it. if ($make_group_also && !getgrnam($new_name)) { log_info( mtx("Adding new group `%s' (GID %d) ..."), $new_name, $gid_option ); $undogroup = $new_name; my $groupadd = &which('groupadd'); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($groupadd, '--extrausers', '-g', $gid_option, $new_name); } else { &systemcall($groupadd, '-g', $gid_option, $new_name); } } log_info( mtx("Adding new user `%s' (UID %d) with group `%s' ..."), $new_name, $new_uid, $ingroup_name ); $home_dir = $special_home || $uid_pool{$new_name}{'home'} || '/nonexistent'; $no_create_home = $home_dir =~ /^\/+nonexistent(\/|$)/ ? 1 : $no_create_home; $shell = $special_shell || $uid_pool{$new_name}{'shell'} || '/usr/sbin/nologin'; $undouser = $new_name; if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall('/usr/sbin/useradd', '--extrausers', '-r', '-K', sprintf('SYS_UID_MIN=%d', $config{'first_system_uid'}), '-K', sprintf('SYS_UID_MAX=%d', $config{'last_system_uid'}), '-d', $home_dir, '-g', $ingroup_name, '-s', $shell, '-u', $new_uid, $new_name); } else { &systemcall('/usr/sbin/useradd', '-r', '-K', sprintf('SYS_UID_MIN=%d', $config{'first_system_uid'}), '-K', sprintf('SYS_UID_MAX=%d', $config{'last_system_uid'}), '-d', $home_dir, '-g', $ingroup_name, '-s', $shell, '-u', $new_uid, $new_name); } release_lock(0); if (defined($new_comment)) { &ch_comment($new_comment); } elsif ($uid_pool{$new_name}{'comment'}) { &ch_comment($uid_pool{$new_name}{'comment'}); } $primary_gid = $gid_option; create_homedir(0); exit( RET_OK ); } ############# ## adduser ## ############# if ($action eq "adduser") { acquire_lock(); $primary_gid=-1; my @supplemental_groups=(); log_trace( "new_uid %s", $new_uid ); log_trace( "ingroup_name %s, gid_option %s", $ingroup_name, $gid_option ); log_trace( "usergroups %s", $config{"usergroups"} ); log_trace( "users_gid %s, users_group %s", $config{"users_gid"}, $config{"users_group"} ); log_trace( "primary_gid %s, supplemental groups %s", $primary_gid, join(", ",@supplemental_groups) ); if( defined($config{"users_gid"}) && defined($config{"users_group"}) ) { log_warn ( mtx("USERS_GID and USERS_GROUP both given in configuration. This is an error.") ); log_fatal (mtx("The user `%s' was not created."),$new_name); exit( RET_CONFIG_ERROR ); } if ($config{"usergroups"} =~ /yes/i) { log_trace( "config usergroups == yes code path" ); $make_group_also = 1; if( $gid_option ) { $make_group_also = 0; $primary_gid = $gid_option; log_trace( "gid_option defined %s, make_group_also 0, primary_gid=gid_option", $gid_option ); } if( $ingroup_name ) { $make_group_also = 0; $primary_gid = getgrnam($ingroup_name); log_trace( "ingroup_name defined %s, make_group_also 0, primary_gid %s", $gid_option, $primary_gid ); } log_trace( "make_group_also %s, primary_gid %s", $make_group_also, $primary_gid ); if( defined( $primary_gid) && $primary_gid == -1 && $make_group_also == 0 ) { if (defined($config{"users_gid"}) && $config{"users_gid"} != -1) { my @grgid=getgrgid($config{"users_gid"}); my $grname=$grgid[0]; log_debug( "set primary_gid to users_gid %s %s", $config{"users_gid"}, $grname); $primary_gid = $config{"users_gid"}; } elsif (defined($config{"users_gid"}) && $config{"users_gid"} == -1) { # nothing } else { my $primary_group="users"; if (defined($config{"users_group"})) { $primary_group=$config{"users_group"}; } $primary_gid=getgrnam($primary_group); log_debug( "set primary_gid to users_group %s %s", $primary_gid, $primary_group); } } else { if (defined($config{"users_gid"}) && $config{"users_gid"} != -1) { my @grgid=getgrgid($config{"users_gid"}); my $grname=$grgid[0]; log_trace( "push users_gid %s %s to supplemental_groups", $config{"users_gid"}, $grname); push(@supplemental_groups, $grname); } elsif (defined($config{"users_gid"}) && $config{"users_gid"} == -1) { # nothing } else { my $supp_group="users"; if (defined($config{"users_group"})) { $supp_group=$config{"users_group"}; } log_trace( "push %s to supplemental_groups", $supp_group ); push(@supplemental_groups, $supp_group); } } } else { log_debug( "config usergroups != yes code path" ); if( defined($ingroup_name) ) { $primary_gid=getgrnam($ingroup_name); } elsif (defined($config{"users_gid"})) { log_trace( "primary_gid = users_gid = %d", $primary_gid ); $primary_gid = $config{"users_gid"}; } else { if (defined($config{"users_group"})) { my @grgid=getgrnam($config{"users_group"}); my $grgid=$grgid[2]; log_trace( "primary_gid = users_group %s %s", $config{"users_group"}, $grgid); $primary_gid = $grgid; } else { log_trace( "primary_gid = literal 100"); $primary_gid = 100; } } if( $primary_gid == -1 ) { log_fatal( "no primary GID for user set. User not created." ); exit( RET_NO_PRIMARY_GID ); } } log_debug( "primary_gid %s, supplemental groups %s", $primary_gid, join(", ",@supplemental_groups) ); if ( defined $ingroup_name || defined $gid_option ) { $make_group_also = 0; log_trace( "set make_group_also 0, neither ingroup_name or gid_option defined" ); } check_user_group(0); $first_uid = $new_firstuid || $config{"first_uid"}; $last_uid = $new_lastuid || $config{"last_uid"}; if ($config{"usergroups"} =~ /yes/i) { $first_gid = $first_uid; $last_gid = $last_uid; } else { $first_gid = $new_firstgid || $config{"first_gid"}; $last_gid = $new_lastgid || $config{"last_gid"}; } log_trace( "first_uid %s, last_uid %s, first_gid %s, last_gid %s", $first_uid, $last_uid, $first_gid, $last_gid ); log_info (gtx("Adding user `%s' ..."),$new_name); if (!defined($new_uid)) { if ( defined $ingroup_name ) { $new_uid = &first_avail_uid( $first_uid, $last_uid, $uid_pool{$new_name}{'id'}); } else { my $first_uidgid = ($first_uid, $first_gid)[$first_uid > $first_gid]; my $last_uidgid = ($last_uid, $last_gid)[$last_uid < $last_gid]; # TODO: Check what happens when those ranges do not overlap $new_uid = &first_avail_uid_gid( $first_uidgid, $last_uidgid, $uid_pool{$new_name}{'id'}); log_trace( "uidgid=%s, from first_uidgid %s, last_uidgid %s", $new_uid, $first_uidgid, $last_uidgid); } # TODO: user can specify different UID and GID here. # idea: split handling in uid/gid, which are equally the return value of # first_avail_uid_gid. If either pool_id is defined, set uid and gid from # distinct first_avail_uid and first_avail_gid calls. log_debug( "new_uid %s selected", $new_uid); if ($new_uid == -1) { log_warn( mtx("No UID/GID pair is available in the range %d-%d (FIRST_UID - LAST_UID)."), $first_uid, $last_uid); log_fatal( mtx("The user `%s' was not created."), $new_name ); exit( RET_NO_ID_IN_RANGE ); } log_trace( "gid_option %s, ingroup_name %s", $gid_option, $ingroup_name ); if ( defined $gid_option && $gid_option == -1 && defined $ingroup_name && $ingroup_name == "") { log_warn( mtx("USERGROUPS=no, USER_GID=-1 and USERS_GROUP empty. A user needs a primary group!") ); log_fatal( mtx("The user `%s' was not created."), $new_name ); exit( RET_NO_PRIMARY_GROUP ); } elsif (defined($gid_option) && $gid_option != -1) { $ingroup_name = getgrgid($gid_option); $primary_gid = $gid_option; log_debug( "gid_option defined and not -1, ingroup_name %s, primary_gid %d", $ingroup_name, $primary_gid ); } elsif ($ingroup_name) { $primary_gid = getgrnam($ingroup_name); log_debug( "ingroup_name defined %s, primary_gid %d", $ingroup_name, $primary_gid ); } elsif ( defined( $primary_gid ) ) { $ingroup_name = getgrgid($primary_gid); log_debug( "primary_gid defined %d, ingroup_name %s", $primary_gid, $primary_gid ); } else { $ingroup_name = 'users'; $primary_gid = 100; log_debug( "ingroup_name hard users, primary_gid hard 100" ); } if ($make_group_also) { $primary_gid = $new_uid; $ingroup_name = $new_name; log_trace( "make_group_also %s, primary_gid %s, ingroup_name %s", $make_group_also, $primary_gid, $ingroup_name ); } } else { log_debug( "new_uid %s, primary_gid %s, ingroup_name %s, make_group_also %s", $new_uid, $primary_gid, $ingroup_name, $make_group_also ); if (defined($gid_option)) { $ingroup_name = getgrgid($gid_option); $primary_gid = $gid_option; log_debug( "gid_option defined %s, ingroup_name %s", $gid_option, $ingroup_name ); } elsif (defined($primary_gid) && $primary_gid != -1) { $ingroup_name = getgrgid($primary_gid); log_debug( "primary_gid defined %s, ingroup_name %s", $primary_gid, $ingroup_name ); } elsif ($ingroup_name) { $primary_gid = getgrnam($ingroup_name); log_debug( "ingroup_name defined %s, primary_gid %s", $ingroup_name, $primary_gid ); } elsif ($make_group_also) { $primary_gid=$new_uid; $ingroup_name=$new_name; log_debug( "make_group_also %s, primary_gid defined %s, ingroup_name %s", $make_group_also, $primary_gid, $ingroup_name ); } else { log_debug( "no gid_option, no primary_gid, no ingroup_name, no make_group_also" ); log_fatal( mtx("Internal error interpreting parameter combination") ); exit( RET_INTERNAL ); } } log_debug ("make_group_also %s", $make_group_also ); if ($make_group_also) { $undogroup = $new_name; my $groupadd = &which('groupadd'); if( defined( $primary_gid ) ) { log_info( mtx("Adding new group `%s' (%d) ..."), $new_name, $primary_gid); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($groupadd, '--extrausers', '-g', $primary_gid, $new_name); } else { &systemcall($groupadd, '-g', $primary_gid, $new_name); } } else { log_info( mtx("Adding new group `%s' (new group ID) ..."), $new_name); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($groupadd, '--extrausers', $new_name); } else { &systemcall($groupadd, $new_name); } $primary_gid = getgrnam($new_name); log_info( mtx("new group '%s' created with GID %d"), $new_name, $primary_gid ); } } { my @grgid=getgrgid($primary_gid); my $grname=$grgid[0]; log_info( mtx("Adding new user `%s' (%d) with group `%s (%d)' ..."), $new_name, $new_uid, $grname, $primary_gid ); } $home_dir = $special_home || $uid_pool{$new_name}{'home'} || &homedir($new_name, $ingroup_name); if( !$disabled_login ) { $shell = $special_shell || $uid_pool{$new_name}{'shell'} || $config{"dshell"}; } else { $shell = $special_shell || $uid_pool{$new_name}{'shell'} || "/usr/sbin/nologin"; } log_debug( "creating new user with home_dir %s and shell %s", $home_dir, $shell ); $undouser = $new_name; my $useradd = &which('useradd'); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($useradd, '--extrausers', '-d', $home_dir, '-g', $primary_gid, '-s', $shell, '-u', $new_uid, $new_name); } else { &systemcall($useradd, '-d', $home_dir, '-g', $primary_gid, '-s', $shell, '-u', $new_uid, $new_name); } create_homedir (1); # copy skeleton data # useradd without -p has left the account disabled (password string is '!') my $yesexpr = langinfo(YESEXPR()); my $noexpr = langinfo(NOEXPR()); if ($ask_passwd) { PASSWD: for (;;) { my $passwd = &which('passwd'); # do _not_ use systemcall() here, since systemcall() dies on # non-zero exit code and we need to do special handling here! system($passwd, $new_name); my $ok = $?>>8; if ($ok != 0) { my $answer; # hm, error, should we break now? log_warn( mtx("Permission denied")) if ($ok == 1); log_warn( mtx("invalid combination of options")) if ($ok == 2); log_warn( mtx("unexpected failure, nothing done")) if ($ok == 3); log_warn( mtx("unexpected failure, passwd file missing")) if ($ok == 4); log_warn( mtx("passwd file busy, try again")) if ($ok == 5); log_warn( mtx("invalid argument to option")) if ($ok == 6); # Translators: [y/N] has to be replaced by values defined in your # locale. You can see by running "locale noexpr" which regular # expression will be checked to find positive answer. PROMPT: for (;;) { print (gtx("Try again? [y/N] ")); chop ($answer=); last PROMPT if ($answer =~ m/$yesexpr/o); last PASSWD if ($answer =~ m/$noexpr/o); last PASSWD if (!$answer); } } else { last; ## passwd ok } } } if (defined($new_comment)) { &ch_comment($new_comment); } elsif ($uid_pool{$new_name}{'comment'}) { &ch_comment($uid_pool{$new_name}{'comment'}); } else { my $noexpr = langinfo(NOEXPR()); my $yesexpr = langinfo(YESEXPR()); CHFN: for (;;) { my $chfn = &which('chfn'); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($chfn, '--extrausers', $new_name); } else { &systemcall($chfn, $new_name); } # Translators: [y/N] has to be replaced by values defined in your # locale. You can see by running "locale yesexpr" which regular # expression will be checked to find positive answer. PROMPT: for (;;) { print (gtx("Is the information correct? [Y/n] ")); chop (my $answer=); last PROMPT if ($answer =~ m/$noexpr/o); last CHFN if ($answer =~ m/$yesexpr/o); last CHFN if (!$answer); } } } if ( ( $add_extra_groups || $config{"add_extra_groups"} ) && defined($config{"extra_groups"}) ) { log_debug( "add extra_groups from config (%s) to supplemental_groups", $config{"extra_groups"} ); push (@supplemental_groups, split(/\s+/,$config{"extra_groups"})); } if ( @supplemental_groups ) { log_info( mtx("Adding new user `%s' to supplemental / extra groups `%s' ..."), $new_name, join(", ", @supplemental_groups) ); foreach my $newgrp ( @supplemental_groups ) { log_trace( "newgrp %s", $newgrp ); if (!defined getgrnam($newgrp)) { log_warn( mtx("The group `%s' does not exist."), $newgrp); next; } if (&user_is_member($new_name, $newgrp)) { log_info( mtx("The user `%s' is already a member of `%s'."), $new_name,$newgrp ); next; } log_info( mtx("Adding user `%s' to group `%s' ..."), $new_name, $newgrp ); my $gpasswd = &which('gpasswd'); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($gpasswd, '--extrausers', '-M', join(',', get_group_members($newgrp), $new_name), $newgrp); } else { &systemcall($gpasswd, '-M', join(',', get_group_members($newgrp), $new_name), $newgrp); } } } if ($config{"quotauser"}) { log_info( mtx("Setting quota for user `%s' to values of user `%s' ..."), $new_name, $config{quotauser} ); my $edquota = &which('edquota'); &systemcall($edquota, '-p', $config{quotauser}, $new_name); } &systemcall('/usr/local/sbin/adduser.local', $new_name, $new_uid, $primary_gid, $home_dir) if (-x "/usr/local/sbin/adduser.local"); release_lock(0); exit( RET_OK ); } # # we never go here # # calculate home directory sub homedir { my $dir = $config{"dhome"}; $dir .= '/' . $_[1] if ($config{"grouphomes"} =~ /yes/i); $dir .= '/' . substr($_[0],0,1) if ($config{"letterhomes"} =~ /yes/i); $dir .= '/' . $_[0]; return $dir; } # create_homedir -- create the homedirectory # parameter # 1: $copy_skeleton: # if 0 -> do not copy the skeleton data # if 1 -> copy the files in /etc/skel to the newly created home directory # return values: # none sub create_homedir { my ($copy_skeleton) = @_; if ($home_dir =~ /^\/+nonexistent(\/|$)/) { log_info( mtx("Not creating `%s'."), $home_dir ); } elsif ($no_create_home) { log_info( mtx("Not creating home directory `%s'."), $home_dir ); } elsif (-e $home_dir) { log_warn( mtx("The home directory `%s' already exists. Not touching this directory."), $home_dir ); my @homedir_stat = stat($home_dir); my $home_uid = $homedir_stat[4]; my $home_gid = $homedir_stat[5]; if (($home_uid != $new_uid) || ($home_gid != $primary_gid)) { log_warn( mtx("Warning: The home directory `%s' does not belong to the user you are currently creating."), $home_dir ); } } else { log_info( mtx("Creating home directory `%s' ..."),$home_dir ); $undohome = $home_dir; if( !&mktree($home_dir) ) { log_err( gtx("Couldn't create home directory `%s': %s."), $home_dir, $!); &cleanup(); } if ($action eq "adduser") { # Mute the command system('sh' => ( '-c' => '"$@" >/dev/null 2>&1', '--', '/usr/sbin/zsysctl', 'userdata', 'create', $new_name, $home_dir,)); } if( !chown($new_uid, $primary_gid, $home_dir) ) { log_err("chown %s:%s %s: %s", $new_uid, $primary_gid, $home_dir, $!); &cleanup(); } $dir_mode = get_dir_mode(); if( !chmod ($dir_mode, $home_dir) ) { log_err("chmod %s %s: %s", $dir_mode, $home_dir, $!); &cleanup(); } if (defined($encrypt_home)) { printf gtx("Setting up encryption ...\n") if $verbose; &systemcall($ecryptfs_setup_private, '-b', '-u', $new_name); } if ($config{"skel"} && $copy_skeleton) { log_info( mtx("Copying files from `%s' ..."), $config{skel} ); my $findpipe; if( !open($findpipe, q{-|}, "cd $config{skel}; find . -print") ) { log_err( mtx("fork for `find' failed: %s"), $!); &cleanup(); } while (<$findpipe>) { chop; next if ($_ eq "."); next if ($_ =~ qr/$config{skel_ignore_regex}/ ); ©_to_dir($config{"skel"}, $_, $home_dir, $new_uid, $primary_gid, ($config{"setgid_home"} =~ /yes/i)); } close ($findpipe); } if (defined($encrypt_home)) { &systemcall("/bin/umount", $home_dir); } } } # mktree: create a directory and all parent directories # we do not care about the rights and so on # parameters: # tree: the path # return values: # none sub mktree { my($tree) = @_; my($done, @path); my $default_dir_mode = oct(755); $tree =~ s:^/*(.*)/*$:$1:; # chop off leading & trailing slashes @path = split(/\//, $tree); $done = ""; while (@path) { $done .= '/' . shift(@path); -d $done || mkdir($done, $default_dir_mode) || return 0; } return 1; } # existing_user_ok: check if there is already a user present # on the system which satisfies the requirements # parameter: # new_name: the name of the user to check # new_uid : the UID of the user # return values: # 0 if the the user does not exist # 1 if the user already exists with the specified uid # (or $new_uid was not specified) # 2 if the user already exists, but $new_uid does not match its uid sub existing_user_ok { my($new_name,$new_uid) = @_; my ($dummy1,$dummy2,$uid); if (($dummy1,$dummy2,$uid) = getpwnam($new_name)) { if( defined($new_uid) && $uid == $new_uid ) { return 1; } if (! defined($new_uid)) { return 1; } # TODO: do we really need this code? Range check should not be performed here # also, we might be checking a normal user as well here if( $uid >= $config{"first_system_uid"} && $uid <= $config{"last_system_uid" } ) { return 2; } } else { return 0; } } # existing_group_ok: check if there is already a group which satiesfies the requirements # parameter: # new_name: the name of the group # new_gid : the GID of the group # return values: # 0 if the group does not exist # 1 if the group already exists with the specified gid # (or $gid_option was not specified) # 2 if the group already exists, but $gid_option does not match its gid # 3 if the group already exists inside the system range sub existing_group_ok { my($new_name,$new_gid) = @_; my ($dummy1,$dummy2,$gid); if (($dummy1,$dummy2,$gid) = getgrnam($new_name)) { # TODO: is this check required? There should not be any # gid outside of our allowed range anyways ... # also, we might be checking a normal user as well here if( $gid >= $config{"first_system_gid"} && $gid <= $config{"last_system_gid" } ) { return 3; } if (! defined($new_gid)) { return 1; } if ($gid == $new_gid) { return 1; } else { return 2; } } else { return 0; } } # check_user_group: ??? # parameters: # system: 0 if the user is not a system user, 1 otherwise # return values: # # todo: not sure whether global variables apply fine here. sub check_user_group { my ($system) = @_; log_debug( "check_user_group %s called, make_group_also %s", $system, $make_group_also ); if( !$system || !existing_user_ok($new_name, $new_uid) ) { if( defined getpwnam($new_name) ) { if( $system ) { log_fatal( mtx("The user `%s' already exists, and is not a system user."), $new_name); exit( RET_WRONG_OBJECT_PROPERTIES ); } else { log_fatal( mtx("The user `%s' already exists."), $new_name); exit( RET_OBJECT_EXISTS ); } } if (defined($new_uid) && getpwuid($new_uid)) { log_fatal( mtx("The UID %d is already in use."), $new_uid); exit( RET_ID_IN_USE ); } } if ($make_group_also) { log_trace( "make_group_also 1, new_name %s, new_uid %s", $new_name, $new_uid ); if( !$system || !existing_group_ok($new_name, $new_uid) ) { if (defined getgrnam($new_name)) { log_fatal( mtx("The group `%s' already exists."),$new_name ); exit( RET_OBJECT_EXISTS ); } if (defined($new_uid) && defined(getgrgid($new_uid))) { log_fatal( mtx("The GID %d is already in use."),$new_uid ); exit( RET_ID_IN_USE ); } } } else { if ($ingroup_name && !defined(getgrnam($ingroup_name))) { log_fatal( mtx("The group `%s' does not exist."), $ingroup_name); exit( RET_OBJECT_DOES_NOT_EXIST ); } if (defined($gid_option) && !defined(getgrgid($gid_option))) { log_fatal( mtx("No group with GID %d found."), $gid_option); exit( RET_OBJECT_DOES_NOT_EXIST ); } } log_debug( "return from check_user_group" ); } # copy_to_dir : # parameters: # fromdir # file # todir # newi # newg # sgiddir # return values: # none sub copy_to_dir { my($fromdir, $file, $todir, $newu, $newg, $sgiddir) = @_; if (-l "$fromdir/$file") { my $target; if( !($target = readlink("$fromdir/$file")) ) { log_err( "readlink: %s", $! ); &cleanup(); } my $curgid="$)"; my $curuid="$>"; my $error=""; $)="$newg"; $>="$newu"; symlink("$target", "$todir/$file") or $error="$!"; $>="$curuid"; $)="$curgid"; if( "$error" ne "" ) { log_err( "symlink: %s", $!); &cleanup(); } return; } elsif (-f "$fromdir/$file") { my $filefh; my $newfilefh; if( !open ($filefh, q{<}, "$fromdir/$file") ) { log_err( "open %s/%s: %s", $fromdir, $file , $!); &cleanup(); } if( !open ($newfilefh, q{>}, "$todir/$file") ) { log_err( "open >%s/%s: %s", $todir, $file, $!); &cleanup(); } if( !print $newfilefh (<$filefh>) ) { log_err( "print %s/%s: %s", $todir, $file, $!); &cleanup(); } close($filefh); if( !close($newfilefh) ) { log_err( "close %s/%s: %s", $todir, $file, $!); &cleanup(); } } elsif (-d "$fromdir/$file") { if( !mkdir("$todir/$file", 700) ) { log_err( "mkdir: %s/%s: %s", $todir, $file, $!); &cleanup(); } } else { log_err( mtx("%s/%s is neither a dir, file, nor a symlink."), $fromdir, $file ); &cleanup(); } if( !chown($newu, $newg, "$todir/$file") ) { log_err( "chown %s:%s %s/%s: %s", $newu, $newg, $todir, $file, $! ); &cleanup(); } $perm = (stat("$fromdir/$file"))[2] & oct(7777); if (-d "$fromdir/$file" && ($perm & oct(10)) && $sgiddir) { $perm |= oct(2000); } if( !chmod($perm, "$todir/$file") ) { log_err( "chmod %s/%s: %s", $todir, $file, $!); &cleanup(); } } # checkname: perform some sanity checks # parameters: # name: the name to check # return values: # none (exits on error) sub checkname { my ($name) = @_; my $ieee_regex = '^[_.A-Za-z0-9][-\@_.A-Za-z0-9]*\$?$'; my $min_regex = qr{^[^-+~:,\s/][^:,\s/]*$}; my $name_regex_var = $found_sys_opt ? 'SYS_NAME_REGEX' : 'NAME_REGEX'; my $name_regex = $config{lc $name_regex_var}; if ($name =~ /^[\d]+$/) { # this check cannot be turned off log_err( mtx("To avoid ambiguity with numerical UIDs, usernames which consist of only digits are not allowed.") ); exit( RET_INVALID_CHARS_IN_NAME ); } if (length $name > 32) { # this check cannot be turned off log_err( mtx("Usernames must be no more than 32 bytes in length; note that if you are using Unicode characters, the character limit will be less than 32.") ); exit( RET_INVALID_CHARS_IN_NAME ); } if ($name !~ $min_regex) { # this check cannot be turned off log_err( mtx("To avoid problems, the username must not start with a dash, plus sign, or tilde, and it must not contain any of the following: colon, comma, slash, or any whitespace characters including spaces, tabs, and newlines.") ); exit( RET_INVALID_CHARS_IN_NAME ); } return if ($name =~ qr/$name_regex/); if ($name !~ $ieee_regex && $name_check_level < 2) { log_err( mtx("To avoid problems, the username should consist only of letters, digits, underscores, periods, at signs and dashes, and not start with a dash (as defined by IEEE Std 1003.1-2001). For compatibility with Samba machine accounts, \$ is also supported at the end of the username. (Use the `--allow-all-names' option to bypass this restriction.)") ); exit( RET_INVALID_CHARS_IN_NAME ); } if ($name_check_level) { log_info( mtx("Allowing use of questionable username.") ); } else { log_err( mtx("Please enter a username matching the regular expression configured via the %s configuration variable. Use the `--allow-bad-names' option to relax this check or reconfigure %s in configuration."), $name_regex_var, $name_regex_var ); exit( RET_INVALID_CHARS_IN_NAME ); } } # first_avail_uid: return the first available uid in given range # parameters: # min, max: the range # pool_id: user id suggested from pool # return values: # -1 if no free uid is available # otherwise the choosen uid sub first_avail_uid { my ($min, $max, $pool_id) = @_; if (defined ($pool_id)) { return $pool_id if (!defined(getpwuid($pool_id))); return -1; } log_info( mtx("Selecting UID from range %d to %d ...\n"),$min,$max); my $t = $min; while ($t <= $max) { return $t if (!defined(getpwuid($t))); $t++; } return -1; # nothing available } # first_avail_gid: return the first available gid in given range # parameters: # min, max: the range # pool_id: group id suggested from pool # return values: # -1 if no free gid is available # otherwise the choosen gid sub first_avail_gid { my ($min, $max, $pool_id) = @_; if (defined ($pool_id)) { return $pool_id if (!defined(getgrgid($pool_id))); return -1; } log_info( mtx("Selecting GID from range %d to %d ..."),$min,$max); my $t = $min; while ($t <= $max) { return $t if (!defined(getgrgid($t))); $t++; } return -1; # nothing available } # first_avail_uid_gid: return the first available id in given range # that is both available as uid and gid # parameters: # min, max: the range # pool_id: user id suggested from pool # return values: # -1 if no free id is available # otherwise the choosen id sub first_avail_uid_gid { my ($min, $max, $pool_id) = @_; if (defined ($pool_id)) { return $pool_id if (!defined(getgrgid($pool_id))); return -1; } log_info( mtx("Selecting UID/GID from range %d to %d ..."), $min, $max ); my $t = $min; while ($t <= $max) { return $t if (!defined(getgrgid($t)) && !defined(getpwuid($t))); $t++; } return -1; # nothing available } sub ch_comment { my $chfn = &which('chfn'); my $comment = shift; if($comment =~ /,/) { my($comment_name,$comment_room,$comment_work,$comment_home,$comment_other) = split(/,/,$comment); if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($chfn, '--extrausers', '-f', $comment_name, '-r', $comment_room, $new_name); &systemcall($chfn,'--extrausers','-w',$comment_work,$new_name) if(defined($comment_work)); &systemcall($chfn,'--extrausers','-h',$comment_home,$new_name) if(defined($comment_home)); &systemcall($chfn,'--extrausers','-o',$comment_other,$new_name) if(defined($comment_other)); } else { &systemcall($chfn, '-f', $comment_name, '-r', $comment_room, $new_name); &systemcall($chfn,'-w',$comment_work,$new_name) if(defined($comment_work)); &systemcall($chfn,'-h',$comment_home,$new_name) if(defined($comment_home)); &systemcall($chfn,'-o',$comment_other,$new_name) if(defined($comment_other)); } } else { if ( ($use_extrausers) || ($config{"use_extrausers"}) ) { &systemcall($chfn, '--extrausers', '-f', $comment, $new_name); } else { &systemcall($chfn, '-f', $comment, $new_name); } } } # user is member of group? sub user_is_member { my($user, $group) = @_; for (split(/ /, (getgrnam($group))[3])) { return 1 if ($user eq $_); } return 0; } sub cleanup { if ($undohome) { log_info( mtx("Removing directory `%s' ..."), $undohome); &systemcall('rm', '-rf', $undohome); } if ($undouser) { log_info( mtx("Removing user `%s' ..."), $undouser); &systemcall('userdel', $undouser); } if ($undogroup) { log_info( mtx("Removing group `%s' ..."), $undogroup); &systemcall('groupdel', $undogroup); } exit( RET_ADDUSER_ABORTED ); } sub handler { my($sig) = @_; # Translators: the variable %s is INT, QUIT, or HUP. # Please do not insert a space character between SIG and %s. log_err( mtx( "Caught a SIG%s.", $sig ) ); &cleanup(); } sub version { printf( gtx("adduser version %s\n\n"), $version ); print( gtx("Adds a user or group to the system. For detailed copyright information, please refer to /usr/share/doc/adduser/copyright. \n") ); print( gtx( "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, /usr/share/common-licenses/GPL, for more details. ") ); } sub usage { printf( gtx( "adduser [--uid id] [--firstuid id] [--lastuid id] [--gid id] [--firstgid id] [--lastgid id] [--ingroup group] [--add-extra-groups] [--encrypt-home] [--shell shell] [--comment comment] [--home dir] [--no-create-home] [--allow-all-names] [--allow-bad-names] [--disabled-password] [--disabled-login] [--conf file] [--extrausers] [--quiet] [--verbose] [--debug] user Add a normal user adduser --system [--uid id] [--group] [--ingroup group] [--gid id] [--shell shell] [--comment comment] [--home dir] [--no-create-home] [--conf file] [--extrausers] [--quiet] [--verbose] [--debug] user Add a system user adduser --group [--gid ID] [--firstgid id] [--lastgid id] [--conf file] [--extrausers] [--quiet] [--verbose] [--debug] group addgroup [--gid ID] [--firstgid id] [--lastgid id] [--conf file] [--extrausers] [--quiet] [--verbose] [--debug] group Add a user group addgroup --system [--gid id] [--conf file] [--extrausers] [--quiet] [--verbose] [--debug] group Add a system group adduser [--extrausers] USER GROUP Add an existing user to an existing group\n") ); } sub usage_error { &usage; exit( RET_INVALID_CALL ); } # get_dir_mode: return the appropriate permissions mode for a home directory # parameters: # none # return value: # a valid octal mode sub get_dir_mode { my $setgid = $config{"setgid_home"} =~ /yes/i; my $mode = $found_sys_opt ? $config{"sys_dir_mode"} : $config{"dir_mode"}; if(!defined($mode) || ! ($mode =~ /[0-7]{3}/ || $mode =~ /[0-7]{4}/)) { $mode = ($found_sys_opt) ? "750" : "0750"; } if($setgid && (length($mode) == 3 || $mode =~ /^[0-1|4-5][0-7]{3}$/)) { $mode += 2000; } return oct($mode); } # Local Variables: # mode:cperl # cperl-indent-level:4 # End: # vim: tabstop=4 shiftwidth=4 expandtab