| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <xpap.h> |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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 |
|
| 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 |
|
| 74 |
if( paramlist && *paramlist ){ |
| 75 |
cxpa = xpa; |
| 76 |
|
| 77 |
if( !word(paramlist, host, &lp) ){ |
| 78 |
goto error; |
| 79 |
} |
| 80 |
|
| 81 |
if( !word(paramlist, acl, &lp) ){ |
| 82 |
strcpy(acl, "+"); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 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 |
|
| 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 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 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 |
|
| 152 |
for(ns=xpa->nshead; ns!=NULL; ns=ns->next){ |
| 153 |
|
| 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 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 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 |
|
| 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 |
|
| 203 |
if( (acl == NULL) || (*acl == '\0') ){ |
| 204 |
acl = "+"; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
strcpy(mach, remote); |
| 209 |
if( (ind=strchr(mach, ':')) != NULL ){ |
| 210 |
*ind = '\0'; |
| 211 |
} |
| 212 |
else{ |
| 213 |
return(-1); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
if( xpa ){ |
| 218 |
cur = xpa; |
| 219 |
|
| 220 |
if( strcmp(acl, "-") ){ |
| 221 |
got=XPANSAdd(cur, remote, mode); |
| 222 |
} |
| 223 |
else{ |
| 224 |
got=XPANSDel(cur, remote, mode); |
| 225 |
} |
| 226 |
switch(got){ |
| 227 |
|
| 228 |
case -1: |
| 229 |
return(-1); |
| 230 |
|
| 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 |
|
| 237 |
case 1: |
| 238 |
break; |
| 239 |
} |
| 240 |
} |
| 241 |
else{ |
| 242 |
for(cur=XPAListHead(); cur!=NULL; cur=cur->next){ |
| 243 |
|
| 244 |
if( strcmp(acl, "-") ){ |
| 245 |
got=XPANSAdd(cur, remote, mode); |
| 246 |
} |
| 247 |
else{ |
| 248 |
got=XPANSDel(cur, remote, mode); |
| 249 |
} |
| 250 |
switch(got){ |
| 251 |
|
| 252 |
case -1: |
| 253 |
return(-1); |
| 254 |
|
| 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 |
|
| 261 |
case 1: |
| 262 |
break; |
| 263 |
} |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
return(0); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|