Debian Codegraph @

xpa/remote.c

raw symbols SCIP
1 /*
2 * Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
3 */
4
5 /*
6 *
7 * remote.c -- xpa access control list management
8 *
9 */
10
11 #include <xpap.h>
12
13 /*
14 *----------------------------------------------------------------------------
15 *
16 *
17 * Private Routines
18 *
19 *
20 *----------------------------------------------------------------------------
21 */
22
23 /*
24 *----------------------------------------------------------------------------
25 *
26 *
27 * Semi-Public Routines (used by command.c)
28 *
29 *
30 *----------------------------------------------------------------------------
31 */
32
33 /*
34 *----------------------------------------------------------------------------
35 *
36 * Routine: XPAReceiveRemote
37 *
38 * Purpose: establish remote connection with specified acls
39 *
40 * Returns: xpa callback error codes
41 *
42 *----------------------------------------------------------------------------
43 */
44 #ifdef ANSI_FUNC
45 int
46 XPAReceiveRemote (void *client_data, void *call_data, char *paramlist,
47 char *buf, size_t len)
48 #else
49 int XPAReceiveRemote(client_data, call_data, paramlist, buf, len)
50 void *client_data;
51 void *call_data;
52 char *paramlist;
53 char *buf;
54 size_t len;
55 #endif
56 {
57 XPA xpa = (XPA)call_data;
58 XPA cxpa;
59 char *mode=NULL;
60 char host[SZ_LINE];
61 char acl[SZ_LINE];
62 char which[SZ_LINE];
63 char tbuf[SZ_LINE];
64 int lp=0;
65
66 /* make sure we are using inet sockets */
67 if( XPAMtype() != XPA_INET ){
68 snprintf(tbuf, SZ_LINE, "remote requires that XPA_METHOD be 'inet'\n");
69 XPAError(xpa, tbuf);
70 return(-1);
71 }
72
73 /* see if we are connecting to a particular host */
74 if( paramlist && *paramlist ){
75 cxpa = xpa;
76 /* arg1: host */
77 if( !word(paramlist, host, &lp) ){
78 goto error;
79 }
80 /* arg2: acl (optional) or -proxy */
81 if( !word(paramlist, acl, &lp) ){
82 strcpy(acl, "+");
83 }
84 /* arg3: -proxy to set up proxy processing
85 or acl (if other word was -proxy) */
86 else{
87 if( !strcmp(acl, "-proxy") ){
88 mode="proxy=true";
89 if( !word(paramlist, acl, &lp) ){
90 strcpy(acl, "+");
91 }
92 }
93 else if( word(paramlist, which, &lp) ){
94 if( !strcmp(which, "-proxy") ){
95 mode="proxy=true";
96 }
97 else{
98 goto error;
99 }
100 }
101 }
102 /* make the call */
103 if( XPARemote(cxpa, host, acl, mode) >= 0 ){
104 return(0);
105 }
106 else{
107 snprintf(tbuf, SZ_LINE, "remote xpans %s failed to process %s\n",
108 host, xpa->name);
109 XPAError(xpa, tbuf);
110 return(-1);
111 }
112 }
113 else{
114 goto error;
115 }
116
117 error:
118 XPAError(xpa, "syntax error: -remote hostname:port [acl] [-proxy]\n");
119 return(-1);
120 }
121
122 /*
123 *----------------------------------------------------------------------------
124 *
125 * Routine: XPASendRemote
126 *
127 * Purpose: return the list of remotes for this access point
128 *
129 * Returns: 0 for success, -1 for failure
130 *
131 *----------------------------------------------------------------------------
132 */
133 #ifdef ANSI_FUNC
134 int
135 XPASendRemote (void *client_data, void *call_data, char *paramlist,
136 char **buf, size_t *len)
137 #else
138 int XPASendRemote(client_data, call_data, paramlist, buf, len)
139 void *client_data;
140 void *call_data;
141 char *paramlist;
142 char **buf;
143 size_t *len;
144 #endif
145 {
146 XPA xpa = (XPA)call_data;
147 NS ns;
148 int got = 0;
149 char tbuf[SZ_LINE];
150
151 /* list out the remotes */
152 for(ns=xpa->nshead; ns!=NULL; ns=ns->next){
153 /* skip default ns */
154 if( ns->host == NULL ) continue;
155 snprintf(tbuf, SZ_LINE, "%s %x:%d\n", ns->host, ns->ip, ns->port);
156 send(xpa_datafd(xpa), tbuf, strlen(tbuf), 0);
157 got++;
158 }
159 if( got == 0 ){
160 send(xpa_datafd(xpa), "\n", 1, 0);
161 }
162 return(0);
163 }
164
165 /*
166 *----------------------------------------------------------------------------
167 *
168 * Routine: XPARemote
169 *
170 * Purpose: register the specified XPA (or all XPAs) with the named remote
171 * name server using the specified acl
172 *
173 * Returns: none
174 *
175 *----------------------------------------------------------------------------
176 */
177 #ifdef ANSI_FUNC
178 int
179 XPARemote (XPA xpa, char *host, char *acl, char *mode)
180 #else
181 int XPARemote(xpa, host, acl, mode)
182 XPA xpa;
183 char *host;
184 char *acl;
185 char *mode;
186 #endif
187 {
188 int got=0;
189 char remote[SZ_LINE];
190 char mach[SZ_LINE];
191 char lbuf[SZ_LINE];
192 char *ind;
193 XPA cur;
194
195 /* might have to add the "port" to the host to get remote */
196 strncpy(remote, host, SZ_LINE-1);
197 remote[SZ_LINE-1] = '\0';
198 if( (ind=strchr(remote, ':')) == NULL ){
199 strcat(remote, ":$port");
200 }
201
202 /* if no acl is specified, make it '+' */
203 if( (acl == NULL) || (*acl == '\0') ){
204 acl = "+";
205 }
206
207 /* get machine name by removing port suffix */
208 strcpy(mach, remote);
209 if( (ind=strchr(mach, ':')) != NULL ){
210 *ind = '\0';
211 }
212 else{
213 return(-1);
214 }
215
216 /* either process the specified xpa, or do all of them */
217 if( xpa ){
218 cur = xpa;
219 /* acl="-" => delete, else add */
220 if( strcmp(acl, "-") ){
221 got=XPANSAdd(cur, remote, mode);
222 }
223 else{
224 got=XPANSDel(cur, remote, mode);
225 }
226 switch(got){
227 /* error condition */
228 case -1:
229 return(-1);
230 /* OK */
231 case 0:
232 snprintf(lbuf, SZ_LINE, "%s:%s %s %s",
233 cur->xclass, cur->name, mach, acl);
234 XPAAclEdit(lbuf);
235 break;
236 /* entry already exists (OK) */
237 case 1:
238 break;
239 }
240 }
241 else{
242 for(cur=XPAListHead(); cur!=NULL; cur=cur->next){
243 /* acl="-" => delete, else add */
244 if( strcmp(acl, "-") ){
245 got=XPANSAdd(cur, remote, mode);
246 }
247 else{
248 got=XPANSDel(cur, remote, mode);
249 }
250 switch(got){
251 /* error condition */
252 case -1:
253 return(-1);
254 /* OK */
255 case 0:
256 snprintf(lbuf, SZ_LINE, "%s:%s %s %s",
257 cur->xclass, cur->name, mach, acl);
258 XPAAclEdit(lbuf);
259 break;
260 /* entry already exists (OK) */
261 case 1:
262 break;
263 }
264 }
265 }
266
267 /* return OK */
268 return(0);
269 }
270
271 /*
272 *----------------------------------------------------------------------------
273 *
274 *
275 * Public Routines
276 *
277 *
278 *----------------------------------------------------------------------------
279 */
280