|
|
1.1 root 1: /* smuxentry.c - smuxEntry routines */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/snmp/RCS/smuxentry.c,v 7.0 90/02/17 10:36:47 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/snmp/RCS/smuxentry.c,v 7.0 90/02/17 10:36:47 mrose Exp $
9: *
10: * Contributed by NYSERNet Inc. This work was partially supported by the
11: * U.S. Defense Advanced Research Projects Agency and the Rome Air Development
12: * Center of the U.S. Air Force Systems Command under contract number
13: * F30602-88-C-0016.
14: *
15: *
16: * $Log: smuxentry.c,v $
17: * Revision 7.0 90/02/17 10:36:47 mrose
18: * *** empty log message ***
19: *
20: */
21:
22: /*
23: * NOTICE
24: *
25: * Acquisition, use, and distribution of this module and related
26: * materials are subject to the restrictions of a license agreement.
27: * Consult the Preface in the User's Manual for the full terms of
28: * this agreement.
29: *
30: */
31:
32:
33: /* LINTLIBRARY */
34:
35: #include <stdio.h>
36: #include "smux.h"
37: #include "tailor.h"
38:
39: /* DATA */
40:
41: static char *smuxEntries = "snmpd.peers";
42:
43: static FILE *servf = NULL;
44: static int stayopen = 0;
45:
46: static struct smuxEntry ses;
47:
48: /* */
49:
50: int setsmuxEntry (f)
51: int f;
52: {
53: if (servf == NULL)
54: servf = fopen (isodefile (smuxEntries, 0), "r");
55: else
56: rewind (servf);
57: stayopen |= f;
58:
59: return (servf != NULL);
60: }
61:
62:
63: int endsmuxEntry () {
64: if (servf && !stayopen) {
65: (void) fclose (servf);
66: servf = NULL;
67: }
68:
69: return 1;
70: }
71:
72: /* */
73:
74: struct smuxEntry *getsmuxEntry () {
75: int vecp;
76: register int i;
77: register struct smuxEntry *se = &ses;
78: register char *cp;
79: static char buffer[BUFSIZ + 1];
80: static char *vec[NVEC + NSLACK + 1];
81: static unsigned int elements[NELEM + 1];
82:
83: if (servf == NULL
84: && (servf = fopen (isodefile (smuxEntries, 0), "r")) == NULL)
85: return NULL;
86:
87: bzero ((char *) se, sizeof *se);
88:
89: while (fgets (buffer, sizeof buffer, servf) != NULL) {
90: if (*buffer == '#')
91: continue;
92: if (cp = index (buffer, '\n'))
93: *cp = NULL;
94: if ((vecp = str2vec (buffer, vec)) < 3)
95: continue;
96:
97: if ((i = str2elem (vec[1], elements)) <= 1)
98: continue;
99:
100: se -> se_name = vec[0];
101: se -> se_identity.oid_elements = elements;
102: se -> se_identity.oid_nelem = i;
103: se -> se_password = vec[2];
104: se -> se_priority = vecp > 3 ? atoi (vec[3]) : -1;
105:
106: return se;
107: }
108:
109: return NULL;
110: }
111:
112: /* */
113:
114: struct smuxEntry *getsmuxEntrybyname (name)
115: char *name;
116: {
117: register struct smuxEntry *se;
118:
119: (void) setsmuxEntry (0);
120: while (se = getsmuxEntry ())
121: if (strcmp (name, se -> se_name) == 0)
122: break;
123: (void) endsmuxEntry ();
124:
125: return se;
126: }
127:
128: /* */
129:
130: struct smuxEntry *getsmuxEntrybyidentity (identity)
131: OID identity;
132: {
133: register struct smuxEntry *se;
134:
135: (void) setsmuxEntry (0);
136: while (se = getsmuxEntry ())
137: if (oid_cmp (identity, &se -> se_identity) == 0)
138: break;
139: (void) endsmuxEntry ();
140:
141: return se;
142: }
143:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.