File: sudo

package info (click to toggle)
yash 2.43-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,184 kB
  • ctags: 3,159
  • sloc: ansic: 31,766; makefile: 812; sh: 407; sed: 16
file content (112 lines) | stat: -rw-r--r-- 2,758 bytes parent folder | download | duplicates (6)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# (C) 2011 magicant

# Completion script for the "sudo" command.
# Supports sudo 1.8.0.

function completion/sudo {

	typeset OPTIONS ARGOPT PREFIX
	OPTIONS=( #>#
	"A; use a GUI program for password prompt"
	"a:; specify the authentication method"
	"b; run in the background"
	"C:; specify the file descriptor to be closed"
	"c:; specify the login class"
	"D:; specify the debugging level"
	"E; preserve environment variables"
	"e; edit operand files"
	"g:; specify the group to run the command as"
	"H; set \$HOME to target user's home directory"
	"h; print help"
	"i; run the command as a login shell"
	"K; remove cached credentials entirely"
	"k; remove cached credentials or don't cache credentials"
	"l; list commands allowed for the user"
	"n; never prompt for the password"
	"P; preserve supplementary group IDs"
	"p:; specify the prompt string"
	"r:; specify the new security context's role"
	"S; read the password from the standard input rather than the terminal"
	"s; run \$SHELL"
	"t:; specify the new security context's type"
	"U:; specify the user to change from (with -l)"
	"u:; specify the user to change to"
	"V; print version info"
	"v; cache credentials without running a command"
	) #<#

	command -f completion//parseoptions
	case $ARGOPT in
	(-)
		command -f completion//completeoptions
		;;
	(a)
		if command -vf completion//bsd::completeauthmethod >/dev/null 2>&1 ||
				. -AL completion/_bsd; then
			command -f completion//bsd::completeauthmethod
		fi
		;;
	([CD])
		;;
	(c)
		if command -vf completion//bsd::completeauthclass >/dev/null 2>&1 ||
				. -AL completion/_bsd; then
			command -f completion//bsd::completeauthclass
		fi
		;;
	(g)
		complete -P "$PREFIX" -g
		;;
	(p)
		command -f completion/sudo::prompt
		;;
	(r)
		#TODO security context's role
		;;
	(t)
		#TODO security context's type
		;;
	([Uu])
		complete -P "$PREFIX" -u
		;;
	('')
		typeset i=2 edit=false
		while [ $i -le ${WORDS[#]} ]; do
			case ${WORDS[i]} in
				(--) break;;
				(-e) edit=true;;
			esac
			i=$((i+1))
		done
		if $edit; then
			complete -P "$PREFIX" -f
		else
			command -f completion//getoperands
			command -f completion//reexecute
		fi
		;;
	esac

}

function completion/sudo::prompt {

	typeset word="$TARGETWORD"
	word=${word//%%}
	case $word in (*%)
		PREFIX=${TARGETWORD%\%} #>>#
		complete -T -P "$PREFIX" -D "fully qualified domain name" '%H'
		complete -T -P "$PREFIX" -D "host name" '%h'
		complete -T -P "$PREFIX" -D "name of the user whose password is requested" '%p'
		complete -T -P "$PREFIX" -D "name of the user to run the command as" '%U'
		complete -T -P "$PREFIX" -D "name of the user invoking sudo" '%u'
		complete -T -P "$PREFIX" -D "%" '%%'
		return 0 #<<#
	esac

	return 1

}


# vim: set ft=sh ts=8 sts=8 sw=8 noet: