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