summaryrefslogtreecommitdiff
path: root/usr.sbin/named/host/nslookup
blob: 3f449258e865f175729ea8939682d11a47888518 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/sh -
#	$OpenBSD: nslookup,v 1.2 1997/03/12 10:41:55 downsj Exp $
#
#	@(#)nslookup            e07@nikhef.nl (Eric Wassenaar) 940919
#
# Author:	E.Wassenaar, Nikhef-H
# Version:	19-SEP-1994
# Revision:
#
# This utility emulates nslookup as a wrapper to host.
# It performs most, but not all, functions.

exec=echo
exec=

# ----------------------------------------------------------------------
# Setup environment.
# ----------------------------------------------------------------------

# This is where the ``host'' executable lives.
BINDIR=/usr/local/bin

PATH=${BINDIR}:/bin:/usr/bin:/usr/ucb ; export PATH

cmd=`basename $0`

options="[-l]"
usage="Usage: $cmd $options [server]"

# ----------------------------------------------------------------------
# Exit codes from <sysexits.h>
# ----------------------------------------------------------------------

EX_OK=0
EX_USAGE=64
EX_UNAVAILABLE=69

# ----------------------------------------------------------------------
# Setup defaults.
# ----------------------------------------------------------------------

name=""
zone=""

type=""
class=""

server=""

debug=""
verbose=""
norecurse=""
vc=""

# ----------------------------------------------------------------------
# Process arguments.
# ----------------------------------------------------------------------

for i
do
	if [ "X$server" != "X" ]
	then
		echo "$usage" 1>&2 ; exit $EX_USAGE
	fi

	case "$i" in
	-d)	exec=echo		;;
	-l)	server=`hostname`	;;
	-*)	echo "$cmd: Unknown option $i" 1>&2 ; exit $EX_USAGE ;;
	*)	server="$i"		;;
	esac
done

# ----------------------------------------------------------------------
# Choose between BSD or SYSV echo command.
# ----------------------------------------------------------------------

n=`echo -n`
if [ "$n" = "-n" ]
then
	c='\c' ; n=''
else
	n='-n' ; c=''
fi

# ----------------------------------------------------------------------
# Main loop.
# ----------------------------------------------------------------------

trap continue 2

while echo $n "> $c" ; read line
do
	case "$line" in
	"")	continue	;;
	*\**)	continue	;;
	*\!*)	continue	;;
	*\?*)	line="help"	;;
	esac

	set - $line
	command="$1"
	case "$command" in

	help)
		cat <<!
	exit | quit	- exit from the program
	help | ?	- print this help message
	set  | set all	- show all current settings
	set [no]debug	- increase debug output level
	set [no]verbose	- increase verbose output level
	set [no]recurse	- request recursive nameserver queries
	set [no]vc	- use virtual circuit for queries
	set type=TYPE	- query about the given resource record TYPE
	set class=CLASS	- query about the given resource record CLASS
	server SERVER	- contact the explicit server with name SERVER
	server		- show the name of the current explicit SERVER
	NAME		- query for NAME using all current settings
	NAME SERVER	- query for NAME at the given SERVER
	ls ZONE		- generate listing of the given name ZONE
	ls		- generate listing of the last given ZONE
	ls ZONE [>]FILE	- copy resource record output also to FILE
!
		;;

	exit|quit)
		break
		;;

	set)
		option="$2"
		case "$option" in

		""|all)
			echo "name=$name"
			echo "zone=$zone"
			echo "server=$server"
			echo "set type=$type"
			echo "set class=$class"
			echo "set debug=$debug"
			echo "set verbose=$verbose"
			echo "set norecurse=$norecurse"
			echo "set vc=$vc"
			;;

		debug|debu|deb|de|d)
			debug="-d $debug"
			;;

		nodebug|nodebu|nodeb|node|nod)
			debug=""
			;;

		d2)
			debug="-d -d"
			verbose="-v -v"
			;;

		nod2)
			debug=""
			verbose=""
			;;

		verbose|verbos|verbo|verb|ver|ve|v)
			verbose="-v $verbose"
			;;

		noverbose|noverbos|noverbo|noverb|nover|nove|nov)
			verbose=""
			;;

		recurse|recurs|recur|recu|rec|re|r)
			norecurse=""
			;;

		norecurse|norecurs|norecur|norecu|norec|nore|nor)
			norecurse="-r"
			;;

		vc)
			vc="-u"
			;;

		novc)
			vc=""
			;;

		querytype=*|querytyp=*|queryty=*|queryt=*|\
		query=*|quer=*|que=*|qu=*|q=*|\
		type=*|typ=*|ty=*|t=*)
			type=`echo $option | sed 's/.*=//'`
			if [ "X$type" != "X" ]
			then
				type="-t $type"
			fi
			;;

		querytype|querytyp|queryty|queryt|\
		query|quer|que|qu|q|\
		type|typ|ty|t)
			type=""
			;;

		class=*|clas=*|cla=*|cl=*|c=*)
			class=`echo $option | sed 's/.*=//'`
			if [ "X$class" != "X" ]
			then
				class="-c $class"
			fi
			;;

		class*|clas*|cla*|cl*|c*)
			class=""
			;;

		*)
			echo "Unknown option $option"
			;;

		esac
		;;

	server)
		nserver="$2"
		if [ "X$nserver" = "X" ]
		then
			if [ "X$server" = "X" ]
			then
				echo "No server defined"
			else
				echo "server=$server"
			fi
		else
			server="$nserver"
		fi
		;;

	ls)
		nzone="$2"
		if [ "X$nzone" = "X" ]
		then
			if [ "X$zone" = "X" ]
			then
				echo "No zone defined"
				continue
			fi
		else
			zone="$nzone"
		fi

		file=`echo "$3$4" | sed 's/>*//'`
		if [ "X$file" != "X" ]
		then
			file="-f $file"
		fi

		options="$debug $verbose $norecurse $vc $file"
		$exec host $options $type $class -l $zone $nserver
		;;

	[a-zA-Z0-9]*)
		name="$1"

		nserver="$2"
		if [ "X$nserver" = "X" ]
		then
			nserver="$server"
		fi

		options="$debug $verbose $norecurse $vc"
		$exec host $options $type $class $name $nserver
		;;

	*)
		echo "Unknown command $command"
		;;

	esac
done

exit $EX_OK