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
|
From f79dcd208c2d0e09425cda9535c6881ecf22125c Mon Sep 17 00:00:00 2001
From: Xiao-Long Chen <chenxiaolong@cxl.epac.to>
Date: Sun, 13 Apr 2014 01:01:44 -0400
Subject: [PATCH 1/2] guest-account: Use cross-distro commands
---
debian/guest-account.sh | 41 +++++++++++++++++++++++++++++++++--------
1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/debian/guest-account.sh b/debian/guest-account.sh
index 6da5687..0fc3daa 100644
--- a/debian/guest-account.sh
+++ b/debian/guest-account.sh
@@ -20,7 +20,12 @@ fi
add_account ()
{
- HOME=`mktemp -td guest-XXXXXX`
+ NEWHOME=`mktemp -td guest-XXXXXX`
+ # useradd does not accept upper case characters in the username
+ HOME=`echo $NEWHOME | tr '[A-Z]' '[a-z]'`
+ if [ "x$NEWHOME" != "x$HOME" ]; then
+ mv $NEWHOME $HOME
+ fi
USER=`echo $HOME | sed 's/\(.*\)guest/guest/'`
# if $USER already exists, it must be a locked system account with no existing
@@ -46,7 +51,21 @@ add_account ()
fi
else
# does not exist, so create it
- adduser --system --no-create-home --home / --gecos $(gettext "Guest") --group --shell /bin/bash $USER || {
+ # Arch Linux modification: Ubuntu/Debian uses their own adduser package,
+ # which works differently from the own provided by the shadow package.
+ # Instead, use useradd, which works in any distro.
+ #
+ # Only the syntax is changed
+ # adduser -> useradd
+ # --system -> --system
+ # --no-create-home -> --no-create-home
+ # --home -> --home-dir
+ # --gecos -> --comment
+ # --group -> --user-group
+ # --shell -> --shell
+ #
+ #adduser --system --no-create-home --home / --gecos $(gettext "Guest") --group --shell /bin/bash $USER || {
+ useradd --system --no-create-home --home-dir / --comment $(gettext "Guest") --user-group --shell /bin/bash $USER || {
umount "$HOME"
rm -rf "$HOME"
exit 1
@@ -128,7 +147,12 @@ remove_account ()
GUEST_UID=`echo "$PWENT" | cut -f3 -d:`
GUEST_HOME=`echo "$PWENT" | cut -f6 -d:`
- if [ "$GUEST_UID" -ge 500 ]; then
+ # deluser is provided by the adduser package on Debian/Ubuntu. useradd
+ # doesn't have a '--system' parameter, which causes deluser to only delete
+ # system users, so this will be handled using this script.
+ SYS_UID_MIN="$(cat /etc/login.defs | grep SYS_UID_MIN | awk '{print $2}')"
+ SYS_UID_MAX="$(cat /etc/login.defs | grep SYS_UID_MAX | awk '{print $2}')"
+ if [ "$GUEST_UID" -lt "$SYS_UID_MIN" ] || [ "$GUEST_UID" -gt "$SYS_UID_MAX" ]; then
echo "Error: user $GUEST_USER is not a system user."
exit 1
fi
@@ -150,15 +174,16 @@ remove_account ()
# remove leftovers in /tmp
find /tmp -mindepth 1 -maxdepth 1 -uid "$GUEST_UID" -print0 | xargs -0 rm -rf || true
- # remove possible /media/guest-XXXXXX folder
- if [ -d /media/"$GUEST_USER" ]; then
- for dir in $( find /media/"$GUEST_USER" -mindepth 1 -maxdepth 1 ); do
+ # remove possible /run/media/guest-XXXXXX folder
+ if [ -d /run/media/"$GUEST_USER" ]; then
+ for dir in $( find /run/media/"$GUEST_USER" -mindepth 1 -maxdepth 1 ); do
umount "$dir" || true
done
- rmdir /media/"$GUEST_USER" || true
+ rmdir /run/media/"$GUEST_USER" || true
fi
- deluser --system "$GUEST_USER"
+ #deluser --system "$GUEST_USER"
+ userdel "$GUEST_USER"
}
case "$1" in
--
2.3.3
|