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