annotate previous-work/more_control_helpers/sbin/useradd @ 9:a0c0ccd22ca5
progress on setuid wrapper script.
author |
Robert McIntyre <rlm@mit.edu> |
date |
Wed, 09 Jan 2013 04:53:59 +0000 |
parents |
d6bef198ae71 |
children |
|
rev |
line source |
rlm@1
|
1 #!/bin/bash
|
rlm@1
|
2 # Copyright (c) 2000,2004 Matthias S. Benkmann <article AT winterdrache DOT de>
|
rlm@1
|
3 # You may do everything with this code except misrepresent its origin.
|
rlm@1
|
4 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
|
rlm@1
|
5
|
rlm@1
|
6 #
|
rlm@1
|
7 # This is a primitive script to serve as useradd until the real useradd
|
rlm@1
|
8 # has been installed. It has little error checking, so don't pass it anything
|
rlm@1
|
9 # stupid or it'll mess up your /etc/passwd and/or /etc/group file.
|
rlm@1
|
10 #
|
rlm@1
|
11
|
rlm@1
|
12 if [ $# -ne 13 -o z$1 != z-c -o z$3 != z-d -o z$5 != z-g -o z$7 != z-G -o z$9 != z-s -o z${11} != z-u ]; then
|
rlm@1
|
13 echo 1>&2 USAGE: useradd -c description -d home -g maingroup -G addgroup -s shell -u uid login
|
rlm@1
|
14 exit 1
|
rlm@1
|
15 fi
|
rlm@1
|
16
|
rlm@1
|
17 #test if user already exists
|
rlm@1
|
18 grep "^${13}:.*" /etc/passwd
|
rlm@1
|
19 if [ $? -eq 0 ]; then
|
rlm@1
|
20 echo 1>&2 $0: User does already exist
|
rlm@1
|
21 exit 1
|
rlm@1
|
22 fi
|
rlm@1
|
23
|
rlm@1
|
24 g=`grep ^${6}:.\* /etc/group | cut -d : -f 3 -`
|
rlm@1
|
25 if [ z${g} = z ]; then
|
rlm@1
|
26 echo 1>&2 $0: Group ${6} does not exist!
|
rlm@1
|
27 exit 1
|
rlm@1
|
28 fi
|
rlm@1
|
29
|
rlm@1
|
30 grep ^${8}:.\* /etc/group >/dev/null || \
|
rlm@1
|
31 {
|
rlm@1
|
32 echo 1>&2 $0: Group ${8} does not exist!
|
rlm@1
|
33 exit 1
|
rlm@1
|
34 }
|
rlm@1
|
35
|
rlm@1
|
36
|
rlm@1
|
37 cp /etc/passwd /tmp/passwd123456
|
rlm@1
|
38 echo "${13}:x:${12}:$g:$2:$4:${10}" \
|
rlm@1
|
39 | sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd
|
rlm@1
|
40
|
rlm@1
|
41
|
rlm@1
|
42 cp /etc/group /tmp/group123456
|
rlm@1
|
43 sed -e 's/^\('"${8}"':[^:]*:[0-9]*:..*\)$/\1,'"${13}"'/' \
|
rlm@1
|
44 -e 's/^\('"${8}"':[^:]*:[0-9]*\):$/\1:'"${13}"'/' \
|
rlm@1
|
45 /tmp/group123456 >/etc/group
|