Print this page
8485 Remove set but unused variables in usr/src/cmd
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rpcsec.c
+++ new/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rpcsec.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 * Copyright 2012 Milan Jurik. All rights reserved.
26 + * Copyright 2017 Gary Mills
26 27 */
27 28
28 29 #include <sys/types.h>
29 30 #include <sys/errno.h>
30 31 #include <sys/tiuser.h>
31 32 #include <setjmp.h>
32 33
33 34 #include <rpc/types.h>
34 35 #include <rpc/xdr.h>
35 36 #include <rpc/auth.h>
36 37 #include <rpc/clnt.h>
37 38 #include <rpc/rpc_msg.h>
38 39 #include <rpc/rpcsec_gss.h>
39 40 #include <string.h>
40 41 #include "snoop.h"
41 42
42 43 extern jmp_buf xdr_err;
43 44
44 45 struct cache_struct *find_xid();
45 46 char *nameof_prog(int prog);
46 47 static void print_rpc_gss_init_arg(int, struct cache_struct *);
47 48 static void print_rpc_gss_init_res(int);
48 49
49 50 char *
50 51 rpcsec_gss_proc_to_string(unsigned int proc)
51 52 {
52 53 switch (proc) {
53 54 case RPCSEC_GSS_DATA: return "RPCSEC_GSS_DATA"; break;
54 55 case RPCSEC_GSS_INIT: return "RPCSEC_GSS_INIT"; break;
55 56 case RPCSEC_GSS_CONTINUE_INIT:
56 57 return ("RPCSEC_GSS_CONTINUE_INIT");
57 58 case RPCSEC_GSS_DESTROY:
58 59 return ("RPCSEC_GSS_DESTROY");
59 60 default: return ("unknown");
60 61
61 62 }
62 63 }
63 64
64 65
65 66 char *
66 67 rpcsec_gss_service_to_string(rpc_gss_service_t service)
67 68 {
68 69 switch (service) {
69 70 case rpc_gss_svc_none: return "none"; break;
70 71 case rpc_gss_svc_integrity: return "integrity"; break;
71 72 case rpc_gss_svc_privacy: return "privacy"; break;
72 73 default: return "unknown"; break;
73 74
74 75 }
75 76 }
76 77
77 78 /*
78 79 * Print detailed RPCSEC_GSS cred data.
79 80 */
80 81 void
81 82 print_rpcsec_gss_cred(int xid, int authlen)
82 83 {
83 84 unsigned int seq_num;
84 85 unsigned int handle_len;
85 86 unsigned int rpcsec_gss_ver;
86 87 rpc_gss_service_t rpcsec_gss_service;
87 88 unsigned int rpcsec_gss_proc;
88 89 char *handle, *line;
89 90 struct cache_struct *x;
90 91 int pos;
91 92
92 93 pos = getxdr_pos();
93 94 rpcsec_gss_ver = getxdr_u_long();
94 95
95 96 /* see if we know this version or not */
96 97
97 98 if (rpcsec_gss_ver != 1) {
98 99 (void) showxdr_hex(authlen, "[%s]");
99 100 return;
100 101 }
101 102
102 103 rpcsec_gss_proc = getxdr_u_long();
103 104 seq_num = getxdr_u_long();
104 105 rpcsec_gss_service = getxdr_enum();
105 106
106 107 (void) sprintf(get_line(pos, getxdr_pos()),
107 108 " version = %u", rpcsec_gss_ver);
108 109
109 110 (void) sprintf(get_line(pos, getxdr_pos()),
110 111 " gss control procedure = %u (%s)",
111 112 rpcsec_gss_proc,
112 113 rpcsec_gss_proc_to_string(rpcsec_gss_proc));
113 114
114 115 (void) sprintf(get_line(pos, getxdr_pos()),
115 116 " sequence num = %u", seq_num);
116 117
117 118 (void) sprintf(get_line(pos, getxdr_pos()),
118 119 " service = %d (%s)", rpcsec_gss_service,
119 120 rpcsec_gss_service_to_string(rpcsec_gss_service));
120 121 pos = getxdr_pos();
121 122 handle_len = getxdr_u_long();
122 123 handle = getxdr_hex(handle_len);
123 124 line = get_line(pos, getxdr_pos());
124 125 sprintf(line, " handle: length = %d, data = [%s]",
125 126 handle_len, handle);
126 127 x = find_xid(xid);
127 128 if (x) {
128 129 x->xid_gss_proc = rpcsec_gss_proc;
129 130 x->xid_gss_service = rpcsec_gss_service;
130 131 }
131 132 }
132 133
133 134 /*
134 135 * Based on different RPCSEC_GSS services supported, maybe a
135 136 * special handling is needed before printing the arguments.
136 137 *
137 138 * For integrity service : print the sequence number.
138 139 * For privacy service : do not print the arguments.
139 140 */
140 141 int
141 142 rpcsec_gss_pre_proto(int type, int flags, int xid,
142 143 int prog, int vers, int proc)
143 144 {
144 145 int seq;
145 146 struct cache_struct *x;
146 147
147 148 if (! (x = find_xid(xid)))
148 149 return (0);
149 150
150 151 switch (x->xid_gss_service) {
151 152 case rpc_gss_svc_default:
152 153 case rpc_gss_svc_none:
153 154 break; /* standard call args */
154 155 case rpc_gss_svc_integrity:
155 156 /* length of rpc_gss_data_t encoded in the databody_integ */
156 157 getxdr_u_long();
157 158 /* read the seq number */
158 159 seq = getxdr_u_long();
159 160 if (flags & F_ALLSUM) {
160 161 (void) sprintf(get_sum_line(), "%s %c seq_num = %u",
161 162 "RPC RPCSEC_GSS", type == CALL ? 'C' : 'R',
162 163 seq);
163 164 } else if (flags & F_DTAIL) {
164 165 sprintf(get_line(0, 0),
165 166 "RPCSEC_GSS data seq_num = %u", seq);
166 167 show_space();
167 168 }
168 169 /* call args follow */
169 170 break;
170 171 case rpc_gss_svc_privacy: {
171 172 char *progname = nameof_prog(prog);
172 173 char prognum[32];
173 174
174 175 if (*progname == '?') {
175 176 sprintf(prognum, "%d", prog);
176 177 progname = prognum;
177 178 }
178 179
179 180 if (flags & F_SUM || flags & F_ALLSUM) {
180 181 (void) sprintf(get_sum_line(),
181 182 "%s %c %s ver(%d) proc(%d) (data encrypted) ",
182 183 "RPC RPCSEC_GSS", type == CALL ? 'C' : 'R',
183 184 progname, vers, proc);
184 185 } else if (flags & F_DTAIL) {
185 186 unsigned int args_len;
186 187
187 188 args_len = getxdr_u_long();
188 189 sprintf(get_line(0, 0),
189 190 "RPCSEC_GSS %s ver(%d) proc(%d)",
190 191 progname, vers, proc);
191 192 sprintf(get_line(0, 0),
192 193 "(%s args encrypted, len = %d bytes)",
193 194 type == CALL ? "CALL" : "REPLY", args_len);
194 195 show_space();
195 196 }
196 197 }
197 198 return (1);
198 199
199 200 default:
200 201 break;
201 202 }
202 203 return (0);
203 204 }
204 205
205 206 /*
206 207 * Based on different RPCSEC_GSS services supported, maybe a
207 208 * special handling is needed after printing the arguments.
208 209 *
209 210 * For integrity service : print the checksum.
210 211 */
211 212 void
212 213 rpcsec_gss_post_proto(int flags, int xid)
213 214 {
214 215 char *line;
215 216
216 217 struct cache_struct *x;
217 218
218 219 if (! (x = find_xid(xid)))
219 220 return;
220 221
221 222 switch (x->xid_gss_service) {
222 223 case rpc_gss_svc_default:
223 224 case rpc_gss_svc_none:
224 225 case rpc_gss_svc_privacy:
225 226 /* nothing left */
226 227 break;
227 228 case rpc_gss_svc_integrity:
228 229 if (flags & F_ALLSUM) {
229 230 line = get_sum_line();
230 231 sprintf(line, "RPC RPCSEC_GSS C (checksum)");
231 232 } else if (flags & F_DTAIL) {
232 233 unsigned int checksum_len;
233 234 char *checksum;
234 235
235 236 show_header("RPC: ", "RPCSEC_GSS", 0);
236 237 show_space();
237 238 checksum_len = getxdr_u_long();
238 239 checksum = getxdr_hex(checksum_len);
239 240 sprintf(get_line(0, 0),
240 241 "checksum: len = %d", checksum_len);
241 242 sprintf(get_line(0, 0), "[%s]", checksum);
242 243 show_trailer();
243 244 }
244 245 break;
245 246 default:
246 247 break;
247 248 }
248 249 }
249 250
250 251 /*
251 252 * Print RPCSEC_GSS control procedures protocol data,
252 253 * No-op for RPCSEC_GSS_DATA.
253 254 */
254 255 int
255 256 rpcsec_gss_control_proc(int type, int flags, int xid)
256 257 {
257 258 int seq;
258 259
259 260 struct cache_struct *x;
260 261
261 262 if (! (x = find_xid(xid)))
262 263 return (0);
263 264
264 265 if (x->xid_gss_proc != RPCSEC_GSS_DATA) {
265 266 if (flags & F_SUM) {
266 267 if (type == CALL) {
267 268 (void) sprintf(get_sum_line(), "%s %c %u (%s)",
268 269 "RPC RPCSEC_GSS",
269 270 type == CALL ? 'C' : 'R',
270 271 x->xid_gss_proc,
271 272 rpcsec_gss_proc_to_string(x->xid_gss_proc));
272 273 }
273 274 } else if (flags & F_DTAIL) {
274 275 if (x->xid_gss_proc == RPCSEC_GSS_INIT ||
275 276 x->xid_gss_proc == RPCSEC_GSS_CONTINUE_INIT) {
276 277 if (type == CALL) {
277 278 print_rpc_gss_init_arg(flags, x);
278 279 } else {
279 280 print_rpc_gss_init_res(flags);
280 281 }
281 282 }
282 283 }
283 284 return (1);
284 285 }
285 286
↓ open down ↓ |
250 lines elided |
↑ open up ↑ |
286 287 return (0);
287 288 }
288 289
289 290 /*
290 291 * Skip the header RPCSEC_GSS cred data and
291 292 * put service and control type in the xid cache.
292 293 */
293 294 void
294 295 extract_rpcsec_gss_cred_info(int xid)
295 296 {
296 - unsigned int seq_num;
297 297 unsigned int handle_len;
298 - unsigned int flavor_len;
299 298 unsigned int rpcsec_gss_ver;
300 299 rpc_gss_service_t rpcsec_gss_service;
301 300 unsigned int rpcsec_gss_proc;
302 301 struct cache_struct *x;
303 302
304 - flavor_len = getxdr_u_long();
303 + (void) getxdr_u_long();
305 304 rpcsec_gss_ver = getxdr_u_long();
306 305 /* see if we know this version or not */
307 306 if (rpcsec_gss_ver != 1) {
308 307 longjmp(xdr_err, 1);
309 308 }
310 309 rpcsec_gss_proc = getxdr_u_long();
311 - seq_num = getxdr_u_long();
310 + (void) getxdr_u_long();
312 311 rpcsec_gss_service = getxdr_enum();
313 312 /* skip the handle */
314 313 xdr_skip(RNDUP(getxdr_u_long()));
315 314
316 315 if (x = find_xid(xid)) {
317 316 x->xid_gss_service = rpcsec_gss_service;
318 317 x->xid_gss_proc = rpcsec_gss_proc;
319 318 }
320 319
321 320 }
322 321
323 322 /*
324 323 * Print the argument data for the RPCSEC_GSS_INIT control procedure.
325 324 */
326 325 static void
327 326 print_rpc_gss_init_arg(int flags, struct cache_struct *x)
328 327 {
329 328
330 - char *token, *line;
329 + char *line;
331 330 unsigned int token_len;
332 331 int pos = 0;
333 332
334 333 /*
335 334 * see if we need to print out the rpc_gss_init_arg structure
336 335 * or not.
337 336 */
338 337
339 338 if (x->xid_gss_proc != RPCSEC_GSS_INIT &&
340 339 x->xid_gss_proc != RPCSEC_GSS_CONTINUE_INIT) {
341 340 return;
342 341 }
343 342
344 343 /* print it */
345 344
346 345 (void) sprintf(get_line(pos, getxdr_pos()),
347 346 "RPCSEC_GSS_INIT args:");
348 347
349 348 pos = getxdr_pos();
350 349 token_len = getxdr_u_long();
351 - token = getxdr_hex(token_len);
350 + (void) getxdr_hex(token_len);
352 351 line = get_line(pos, getxdr_pos());
353 352 sprintf(line, " gss token: length = %d, data = [%d bytes]",
354 353 token_len, token_len);
355 354
356 355 show_trailer();
357 356 }
358 357
359 358 /*
360 359 * Print the results data for the RPCSEC_GSS_INIT control procedure.
361 360 */
362 361 void
363 362 print_rpc_gss_init_res(int flags)
364 363 {
365 364
366 - char *handle, *token, *line;
365 + char *handle, *line;
367 366 unsigned int token_len, handle_len;
368 367 unsigned int major, minor, seq_window;
369 368
370 369 int pos = 0;
371 370 struct cache_struct *x;
372 371
373 372 /* print it */
374 373
375 374 (void) sprintf(get_line(pos, getxdr_pos()), "RPCSEC_GSS_INIT result:");
376 375
377 376 pos = getxdr_pos();
378 377 handle_len = getxdr_u_long();
379 378 handle = getxdr_hex(handle_len);
380 379 line = get_line(pos, getxdr_pos());
381 380 sprintf(line, " handle: length = %d, data = [%s]",
382 381 handle_len, handle);
383 382 pos = getxdr_pos();
384 383 major = getxdr_u_long();
385 384 minor = getxdr_u_long();
386 385 seq_window = getxdr_u_long();
387 386
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
388 387 (void) sprintf(get_line(pos, getxdr_pos()),
389 388 " gss_major status = %u", major);
390 389
391 390 (void) sprintf(get_line(pos, getxdr_pos()),
392 391 " gss_minor status = %u", minor);
393 392
394 393 (void) sprintf(get_line(pos, getxdr_pos()),
395 394 " sequence window = %u", seq_window);
396 395 pos = getxdr_pos();
397 396 token_len = getxdr_u_long();
398 - token = getxdr_hex(token_len);
397 + (void) getxdr_hex(token_len);
399 398 line = get_line(pos, getxdr_pos());
400 399 sprintf(line, " gss token: length = %d, data = [%d bytes]",
401 400 token_len, token_len);
402 401 show_trailer();
403 402 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX