xref: /titanic_52/usr/src/cmd/ipf/lib/common/optname.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (C) 1993-2001 by Darren Reed.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
5*7c478bd9Sstevel@tonic-gate  *
6*7c478bd9Sstevel@tonic-gate  * $Id: optname.c,v 1.3 2001/06/09 17:09:24 darrenr Exp $
7*7c478bd9Sstevel@tonic-gate  */
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate #include "ipf.h"
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate u_32_t optname(cp, sp, linenum)
13*7c478bd9Sstevel@tonic-gate char ***cp;
14*7c478bd9Sstevel@tonic-gate u_short *sp;
15*7c478bd9Sstevel@tonic-gate int linenum;
16*7c478bd9Sstevel@tonic-gate {
17*7c478bd9Sstevel@tonic-gate 	struct ipopt_names *io, *so;
18*7c478bd9Sstevel@tonic-gate 	u_long msk = 0;
19*7c478bd9Sstevel@tonic-gate 	u_short smsk = 0;
20*7c478bd9Sstevel@tonic-gate 	char *s;
21*7c478bd9Sstevel@tonic-gate 	int sec = 0;
22*7c478bd9Sstevel@tonic-gate 
23*7c478bd9Sstevel@tonic-gate 	for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) {
24*7c478bd9Sstevel@tonic-gate 		for (io = ionames; io->on_name; io++)
25*7c478bd9Sstevel@tonic-gate 			if (!strcasecmp(s, io->on_name)) {
26*7c478bd9Sstevel@tonic-gate 				msk |= io->on_bit;
27*7c478bd9Sstevel@tonic-gate 				break;
28*7c478bd9Sstevel@tonic-gate 			}
29*7c478bd9Sstevel@tonic-gate 		if (!io->on_name) {
30*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%d: unknown IP option name %s\n",
31*7c478bd9Sstevel@tonic-gate 				linenum, s);
32*7c478bd9Sstevel@tonic-gate 			return 0;
33*7c478bd9Sstevel@tonic-gate 		}
34*7c478bd9Sstevel@tonic-gate 		if (!strcasecmp(s, "sec-class"))
35*7c478bd9Sstevel@tonic-gate 			sec = 1;
36*7c478bd9Sstevel@tonic-gate 	}
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate 	if (sec && !*(*cp + 1)) {
39*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%d: missing security level after sec-class\n",
40*7c478bd9Sstevel@tonic-gate 			linenum);
41*7c478bd9Sstevel@tonic-gate 		return 0;
42*7c478bd9Sstevel@tonic-gate 	}
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 	if (sec) {
45*7c478bd9Sstevel@tonic-gate 		(*cp)++;
46*7c478bd9Sstevel@tonic-gate 		for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) {
47*7c478bd9Sstevel@tonic-gate 			for (so = secclass; so->on_name; so++)
48*7c478bd9Sstevel@tonic-gate 				if (!strcasecmp(s, so->on_name)) {
49*7c478bd9Sstevel@tonic-gate 					smsk |= so->on_bit;
50*7c478bd9Sstevel@tonic-gate 					break;
51*7c478bd9Sstevel@tonic-gate 				}
52*7c478bd9Sstevel@tonic-gate 			if (!so->on_name) {
53*7c478bd9Sstevel@tonic-gate 				fprintf(stderr,
54*7c478bd9Sstevel@tonic-gate 					"%d: no such security level: %s\n",
55*7c478bd9Sstevel@tonic-gate 					linenum, s);
56*7c478bd9Sstevel@tonic-gate 				return 0;
57*7c478bd9Sstevel@tonic-gate 			}
58*7c478bd9Sstevel@tonic-gate 		}
59*7c478bd9Sstevel@tonic-gate 		if (smsk)
60*7c478bd9Sstevel@tonic-gate 			*sp = smsk;
61*7c478bd9Sstevel@tonic-gate 	}
62*7c478bd9Sstevel@tonic-gate 	return msk;
63*7c478bd9Sstevel@tonic-gate }
64