Commit d29a024 1 parent 03619c3 commit d29a024 Copy full SHA for d29a024
File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ function usage() {
27
27
printf " -u switch to a different user by user id\n"
28
28
}
29
29
30
+ function check_id() {
31
+ if (( $1 == $2 )) ; then
32
+ printf " Sorry, you can't switch to yourself.\n"
33
+ exit 1;
34
+ fi
35
+ }
36
+
30
37
# exit with an error if being run from screen
31
38
if [ " $STY " != " " ]; then
32
39
printf " Sorry, swuser doesn't work from within screen. I know, I hate it too!\n"
@@ -48,14 +55,20 @@ if [ $# -gt 0 ]; then
48
55
# handle switching to another user by name
49
56
elif [ " $1 " = " -n" ]; then
50
57
shift
58
+ new_id=$( id -u " $1 " )
59
+ check_id $id $new_id
51
60
" $cgsession " -switchToUserID $( id -u " $1 " )
52
61
shift
53
62
# handle switch to another user by id
54
63
elif [ " $1 " = " -u" ]; then
55
64
shift
65
+ check_id $id $1
56
66
" $cgsession " -switchToUserID $1
57
67
shift
58
68
fi
59
69
done
70
+ else
71
+ printf " No switch user action specified.\n\n"
72
+ usage
60
73
fi
61
74
You can’t perform that action at this time.
0 commit comments