[7d4fbcd] | 1 | #include <stdlib.h> |
---|
| 2 | #include <unistd.h> |
---|
| 3 | #include <sys/types.h> |
---|
| 4 | #include <sys/wait.h> |
---|
[4357be8] | 5 | #include <sys/stat.h> |
---|
[7d4fbcd] | 6 | #include <string.h> |
---|
| 7 | #include "owl.h" |
---|
| 8 | |
---|
[1aee7d9] | 9 | static const char fileIdent[] = "$Id$"; |
---|
| 10 | |
---|
[09489b89] | 11 | #ifdef HAVE_LIBZEPHYR |
---|
[8262340] | 12 | Code_t ZResetAuthentication(); |
---|
[09489b89] | 13 | #endif |
---|
[8262340] | 14 | |
---|
[be0a79f] | 15 | int owl_zephyr_initialize() |
---|
| 16 | { |
---|
[09489b89] | 17 | #ifdef HAVE_LIBZEPHYR |
---|
[be0a79f] | 18 | int ret; |
---|
| 19 | |
---|
| 20 | if ((ret = ZInitialize()) != ZERR_NONE) { |
---|
| 21 | com_err("owl",ret,"while initializing"); |
---|
| 22 | return(1); |
---|
| 23 | } |
---|
| 24 | if ((ret = ZOpenPort(NULL)) != ZERR_NONE) { |
---|
| 25 | com_err("owl",ret,"while opening port"); |
---|
| 26 | return(1); |
---|
| 27 | } |
---|
[09489b89] | 28 | #endif |
---|
| 29 | return(0); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | int owl_zephyr_shutdown() |
---|
| 34 | { |
---|
| 35 | #ifdef HAVE_LIBZEPHYR |
---|
| 36 | unsuball(); |
---|
| 37 | ZClosePort(); |
---|
| 38 | #endif |
---|
[be0a79f] | 39 | return(0); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | int owl_zephyr_zpending() |
---|
| 43 | { |
---|
| 44 | #ifdef HAVE_LIBZEPHYR |
---|
| 45 | return(ZPending()); |
---|
| 46 | #else |
---|
| 47 | return(0); |
---|
| 48 | #endif |
---|
| 49 | } |
---|
| 50 | |
---|
[09489b89] | 51 | char *owl_zephyr_get_realm() |
---|
| 52 | { |
---|
| 53 | #ifdef HAVE_LIBZEPHYR |
---|
| 54 | return(ZGetRealm()); |
---|
| 55 | #else |
---|
| 56 | return(""); |
---|
| 57 | #endif |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | char *owl_zephyr_get_sender() |
---|
| 61 | { |
---|
| 62 | #ifdef HAVE_LIBZEPHYR |
---|
| 63 | return(ZGetSender()); |
---|
| 64 | #else |
---|
| 65 | return(""); |
---|
| 66 | #endif |
---|
| 67 | } |
---|
| 68 | |
---|
[2de4f20] | 69 | /* return 0 on success |
---|
| 70 | * -1 on file error |
---|
| 71 | * -2 on subscription error |
---|
| 72 | */ |
---|
[31e48a3] | 73 | int owl_zephyr_loadsubs(char *filename) |
---|
| 74 | { |
---|
[be0a79f] | 75 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 76 | FILE *file; |
---|
| 77 | char *tmp, *start; |
---|
| 78 | char buffer[1024], subsfile[1024]; |
---|
| 79 | ZSubscription_t subs[3001]; |
---|
| 80 | int count, ret, i; |
---|
[4357be8] | 81 | struct stat statbuff; |
---|
[7d4fbcd] | 82 | |
---|
| 83 | if (filename==NULL) { |
---|
| 84 | sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs"); |
---|
| 85 | } else { |
---|
| 86 | strcpy(subsfile, filename); |
---|
| 87 | } |
---|
[8262340] | 88 | |
---|
[4357be8] | 89 | ret=stat(subsfile, &statbuff); |
---|
| 90 | if (ret) return(0); |
---|
| 91 | |
---|
| 92 | ret=0; |
---|
| 93 | |
---|
[8262340] | 94 | ZResetAuthentication(); |
---|
[7d4fbcd] | 95 | /* need to redo this to do chunks, not just bail after 3000 */ |
---|
| 96 | count=0; |
---|
| 97 | file=fopen(subsfile, "r"); |
---|
| 98 | if (file) { |
---|
| 99 | while ( fgets(buffer, 1024, file)!=NULL ) { |
---|
| 100 | if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue; |
---|
| 101 | |
---|
| 102 | if (buffer[0]=='-') { |
---|
| 103 | start=buffer+1; |
---|
| 104 | } else { |
---|
| 105 | start=buffer; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | if (count >= 3000) break; /* also tell the user */ |
---|
| 109 | |
---|
| 110 | /* add it to the list of subs */ |
---|
| 111 | if ((tmp=(char *) strtok(start, ",\n\r"))==NULL) continue; |
---|
| 112 | subs[count].zsub_class=owl_strdup(tmp); |
---|
| 113 | if ((tmp=(char *) strtok(NULL, ",\n\r"))==NULL) continue; |
---|
| 114 | subs[count].zsub_classinst=owl_strdup(tmp); |
---|
| 115 | if ((tmp=(char *) strtok(NULL, " \t\n\r"))==NULL) continue; |
---|
| 116 | subs[count].zsub_recipient=owl_strdup(tmp); |
---|
| 117 | |
---|
| 118 | /* if it started with '-' then add it to the global punt list */ |
---|
| 119 | if (buffer[0]=='-') { |
---|
| 120 | owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | count++; |
---|
| 124 | } |
---|
| 125 | fclose(file); |
---|
| 126 | } else { |
---|
| 127 | count=0; |
---|
| 128 | ret=-1; |
---|
| 129 | } |
---|
| 130 | |
---|
[4357be8] | 131 | /* sub without defaults */ |
---|
| 132 | if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) { |
---|
[252a5c2] | 133 | owl_function_error("Error subscribing to zephyr notifications."); |
---|
[7d4fbcd] | 134 | ret=-2; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /* free stuff */ |
---|
| 138 | for (i=0; i<count; i++) { |
---|
| 139 | owl_free(subs[i].zsub_class); |
---|
| 140 | owl_free(subs[i].zsub_classinst); |
---|
| 141 | owl_free(subs[i].zsub_recipient); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | return(ret); |
---|
[be0a79f] | 145 | #else |
---|
| 146 | return(0); |
---|
| 147 | #endif |
---|
[7d4fbcd] | 148 | } |
---|
| 149 | |
---|
[4357be8] | 150 | int owl_zephyr_loaddefaultsubs() |
---|
| 151 | { |
---|
[40d834a] | 152 | #ifdef HAVE_LIBZEPHYR |
---|
[4357be8] | 153 | ZSubscription_t subs[10]; |
---|
| 154 | |
---|
| 155 | if (ZSubscribeTo(subs,0,0) != ZERR_NONE) { |
---|
| 156 | owl_function_error("Error subscribing to default zephyr notifications."); |
---|
| 157 | return(-1); |
---|
| 158 | } |
---|
| 159 | return(0); |
---|
[40d834a] | 160 | #else |
---|
| 161 | return(0); |
---|
| 162 | #endif |
---|
[4357be8] | 163 | } |
---|
| 164 | |
---|
[31e48a3] | 165 | int owl_zephyr_loadloginsubs(char *filename) |
---|
| 166 | { |
---|
[be0a79f] | 167 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 168 | FILE *file; |
---|
| 169 | ZSubscription_t subs[3001]; |
---|
| 170 | char subsfile[1024], buffer[1024]; |
---|
| 171 | int count, ret, i; |
---|
[4357be8] | 172 | struct stat statbuff; |
---|
[7d4fbcd] | 173 | |
---|
| 174 | if (filename==NULL) { |
---|
| 175 | sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".anyone"); |
---|
| 176 | } else { |
---|
| 177 | strcpy(subsfile, filename); |
---|
| 178 | } |
---|
[4357be8] | 179 | |
---|
| 180 | ret=stat(subsfile, &statbuff); |
---|
| 181 | if (ret) return(0); |
---|
| 182 | |
---|
| 183 | ret=0; |
---|
[7d4fbcd] | 184 | |
---|
[8262340] | 185 | ZResetAuthentication(); |
---|
[7d4fbcd] | 186 | /* need to redo this to do chunks, not just bag out after 3000 */ |
---|
| 187 | count=0; |
---|
| 188 | file=fopen(subsfile, "r"); |
---|
| 189 | if (file) { |
---|
| 190 | while ( fgets(buffer, 1024, file)!=NULL ) { |
---|
| 191 | if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue; |
---|
| 192 | |
---|
| 193 | if (count >= 3000) break; /* also tell the user */ |
---|
| 194 | |
---|
| 195 | buffer[strlen(buffer)-1]='\0'; |
---|
| 196 | subs[count].zsub_class="login"; |
---|
| 197 | subs[count].zsub_recipient="*"; |
---|
| 198 | if (strchr(buffer, '@')) { |
---|
| 199 | subs[count].zsub_classinst=owl_strdup(buffer); |
---|
| 200 | } else { |
---|
[1c6c4d3] | 201 | subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm()); |
---|
[7d4fbcd] | 202 | } |
---|
| 203 | |
---|
| 204 | count++; |
---|
| 205 | } |
---|
| 206 | fclose(file); |
---|
| 207 | } else { |
---|
| 208 | count=0; |
---|
| 209 | ret=-1; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | /* sub with defaults */ |
---|
[7933748] | 213 | if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) { |
---|
[252a5c2] | 214 | owl_function_error("Error subscribing to zephyr notifications."); |
---|
[7d4fbcd] | 215 | ret=-2; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /* free stuff */ |
---|
| 219 | for (i=0; i<count; i++) { |
---|
| 220 | owl_free(subs[i].zsub_classinst); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | return(ret); |
---|
[be0a79f] | 224 | #else |
---|
| 225 | return(0); |
---|
| 226 | #endif |
---|
[7d4fbcd] | 227 | } |
---|
| 228 | |
---|
[31e48a3] | 229 | void unsuball() |
---|
| 230 | { |
---|
[be0a79f] | 231 | #if HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 232 | int ret; |
---|
[8262340] | 233 | |
---|
| 234 | ZResetAuthentication(); |
---|
[7d4fbcd] | 235 | ret=ZCancelSubscriptions(0); |
---|
| 236 | if (ret != ZERR_NONE) { |
---|
| 237 | com_err("owl",ret,"while unsubscribing"); |
---|
| 238 | } |
---|
[be0a79f] | 239 | #endif |
---|
[7d4fbcd] | 240 | } |
---|
| 241 | |
---|
[31e48a3] | 242 | int owl_zephyr_sub(char *class, char *inst, char *recip) |
---|
| 243 | { |
---|
[be0a79f] | 244 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 245 | ZSubscription_t subs[5]; |
---|
| 246 | |
---|
| 247 | subs[0].zsub_class=class; |
---|
| 248 | subs[0].zsub_classinst=inst; |
---|
| 249 | subs[0].zsub_recipient=recip; |
---|
| 250 | |
---|
[8262340] | 251 | ZResetAuthentication(); |
---|
[7d4fbcd] | 252 | if (ZSubscribeTo(subs,1,0) != ZERR_NONE) { |
---|
[97cd00be] | 253 | owl_function_error("Error subbing to <%s,%s,%s>", class, inst, recip); |
---|
| 254 | return(-2); |
---|
[7d4fbcd] | 255 | } |
---|
| 256 | return(0); |
---|
[be0a79f] | 257 | #else |
---|
| 258 | return(0); |
---|
| 259 | #endif |
---|
[7d4fbcd] | 260 | } |
---|
| 261 | |
---|
| 262 | |
---|
[31e48a3] | 263 | int owl_zephyr_unsub(char *class, char *inst, char *recip) |
---|
| 264 | { |
---|
[be0a79f] | 265 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 266 | ZSubscription_t subs[5]; |
---|
| 267 | |
---|
| 268 | subs[0].zsub_class=class; |
---|
| 269 | subs[0].zsub_classinst=inst; |
---|
| 270 | subs[0].zsub_recipient=recip; |
---|
| 271 | |
---|
[8262340] | 272 | ZResetAuthentication(); |
---|
[7d4fbcd] | 273 | if (ZUnsubscribeTo(subs,1,0) != ZERR_NONE) { |
---|
[97cd00be] | 274 | owl_function_error("Error unsubbing from <%s,%s,%s>", class, inst, recip); |
---|
| 275 | return(-2); |
---|
[7d4fbcd] | 276 | } |
---|
| 277 | return(0); |
---|
[be0a79f] | 278 | #else |
---|
| 279 | return(0); |
---|
| 280 | #endif |
---|
[7d4fbcd] | 281 | } |
---|
| 282 | |
---|
[b0430a6] | 283 | /* return a pointer to the data in the Jth field, (NULL terminated by |
---|
| 284 | * definition). Caller must free the return. |
---|
| 285 | */ |
---|
[be0a79f] | 286 | #ifdef HAVE_LIBZEPHYR |
---|
[b0430a6] | 287 | char *owl_zephyr_get_field(ZNotice_t *n, int j) |
---|
[31e48a3] | 288 | { |
---|
[7d4fbcd] | 289 | int i, count, save; |
---|
[b0430a6] | 290 | char *out; |
---|
[7d4fbcd] | 291 | |
---|
| 292 | count=save=0; |
---|
| 293 | for (i=0; i<n->z_message_len; i++) { |
---|
| 294 | if (n->z_message[i]=='\0') { |
---|
| 295 | count++; |
---|
| 296 | if (count==j) { |
---|
| 297 | /* just found the end of the field we're looking for */ |
---|
[b0430a6] | 298 | return(owl_strdup(n->z_message+save)); |
---|
[7d4fbcd] | 299 | } else { |
---|
| 300 | save=i+1; |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | } |
---|
[b0430a6] | 304 | /* catch the last field, which might not be null terminated */ |
---|
[7d4fbcd] | 305 | if (count==j-1) { |
---|
[b0430a6] | 306 | out=owl_malloc(n->z_message_len-save+5); |
---|
| 307 | memcpy(out, n->z_message+save, n->z_message_len-save); |
---|
| 308 | out[n->z_message_len-save]='\0'; |
---|
| 309 | return(out); |
---|
[7d4fbcd] | 310 | } |
---|
[b0430a6] | 311 | |
---|
| 312 | return(owl_strdup("")); |
---|
[7d4fbcd] | 313 | } |
---|
[09489b89] | 314 | #else |
---|
[701a184] | 315 | char *owl_zephyr_get_field(void *n, int j) |
---|
[09489b89] | 316 | { |
---|
[b0430a6] | 317 | return(owl_strdup("")); |
---|
[09489b89] | 318 | } |
---|
[be0a79f] | 319 | #endif |
---|
[7d4fbcd] | 320 | |
---|
[b0430a6] | 321 | |
---|
[be0a79f] | 322 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 323 | int owl_zephyr_get_num_fields(ZNotice_t *n) |
---|
| 324 | { |
---|
[7d4fbcd] | 325 | int i, fields; |
---|
| 326 | |
---|
| 327 | fields=1; |
---|
| 328 | for (i=0; i<n->z_message_len; i++) { |
---|
| 329 | if (n->z_message[i]=='\0') fields++; |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | return(fields); |
---|
| 333 | } |
---|
[09489b89] | 334 | #else |
---|
| 335 | int owl_zephyr_get_num_fields(void *n) |
---|
| 336 | { |
---|
| 337 | return(0); |
---|
| 338 | } |
---|
[be0a79f] | 339 | #endif |
---|
[7d4fbcd] | 340 | |
---|
[be0a79f] | 341 | #ifdef HAVE_LIBZEPHYR |
---|
[bf73bdd] | 342 | /* return a pointer to the message, place the message length in k |
---|
| 343 | * caller must free the return |
---|
| 344 | */ |
---|
[b0430a6] | 345 | char *owl_zephyr_get_message(ZNotice_t *n) |
---|
[31e48a3] | 346 | { |
---|
[405d5e6] | 347 | /* don't let ping messages have a body */ |
---|
[7d4fbcd] | 348 | if (!strcasecmp(n->z_opcode, "ping")) { |
---|
[bf73bdd] | 349 | return(owl_strdup("")); |
---|
[7d4fbcd] | 350 | } |
---|
| 351 | |
---|
[405d5e6] | 352 | /* deal with MIT Athena OLC messages */ |
---|
[fe67f1f] | 353 | if (!strcasecmp(n->z_sender, "olc.matisse@ATHENA.MIT.EDU")) { |
---|
[405d5e6] | 354 | return(owl_zephyr_get_field(n, 1)); |
---|
| 355 | } |
---|
| 356 | |
---|
[b0430a6] | 357 | return(owl_zephyr_get_field(n, 2)); |
---|
[7d4fbcd] | 358 | } |
---|
[be0a79f] | 359 | #endif |
---|
[7d4fbcd] | 360 | |
---|
[be0a79f] | 361 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 362 | char *owl_zephyr_get_zsig(ZNotice_t *n, int *k) |
---|
| 363 | { |
---|
[7d4fbcd] | 364 | /* return a pointer to the zsig if there is one */ |
---|
| 365 | |
---|
[405d5e6] | 366 | /* message length 0? No zsig */ |
---|
[7d4fbcd] | 367 | if (n->z_message_len==0) { |
---|
| 368 | *k=0; |
---|
| 369 | return(""); |
---|
| 370 | } |
---|
[405d5e6] | 371 | |
---|
| 372 | /* No zsig for OLC messages */ |
---|
[fe67f1f] | 373 | if (!strcasecmp(n->z_sender, "olc.matisse@ATHENA.MIT.EDU")) { |
---|
[405d5e6] | 374 | return(""); |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | /* Everything else is field 1 */ |
---|
[7d4fbcd] | 378 | *k=strlen(n->z_message); |
---|
| 379 | return(n->z_message); |
---|
| 380 | } |
---|
[09489b89] | 381 | #else |
---|
| 382 | char *owl_zephyr_get_zsig(void *n, int *k) |
---|
| 383 | { |
---|
| 384 | return(""); |
---|
| 385 | } |
---|
[be0a79f] | 386 | #endif |
---|
[7d4fbcd] | 387 | |
---|
[31e48a3] | 388 | int send_zephyr(char *opcode, char *zsig, char *class, char *instance, char *recipient, char *message) |
---|
| 389 | { |
---|
[be0a79f] | 390 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 391 | int ret; |
---|
| 392 | ZNotice_t notice; |
---|
| 393 | |
---|
| 394 | memset(¬ice, 0, sizeof(notice)); |
---|
| 395 | |
---|
[8262340] | 396 | ZResetAuthentication(); |
---|
[8ba37ec] | 397 | |
---|
| 398 | if (!zsig) zsig=""; |
---|
[8262340] | 399 | |
---|
[7d4fbcd] | 400 | notice.z_kind=ACKED; |
---|
| 401 | notice.z_port=0; |
---|
| 402 | notice.z_class=class; |
---|
| 403 | notice.z_class_inst=instance; |
---|
| 404 | if (!strcmp(recipient, "*") || !strcmp(recipient, "@")) { |
---|
| 405 | notice.z_recipient=""; |
---|
| 406 | } else { |
---|
| 407 | notice.z_recipient=recipient; |
---|
| 408 | } |
---|
| 409 | notice.z_default_format="Class $class, Instance $instance:\nTo: @bold($recipient) at $time $date\nFrom: @bold{$1 <$sender>}\n\n$2"; |
---|
| 410 | notice.z_sender=NULL; |
---|
| 411 | if (opcode) notice.z_opcode=opcode; |
---|
| 412 | |
---|
[56330ff] | 413 | notice.z_message_len=strlen(zsig)+1+strlen(message); |
---|
[7d4fbcd] | 414 | notice.z_message=owl_malloc(notice.z_message_len+10); |
---|
[56330ff] | 415 | strcpy(notice.z_message, zsig); |
---|
| 416 | memcpy(notice.z_message+strlen(zsig)+1, message, strlen(message)); |
---|
[7d4fbcd] | 417 | |
---|
| 418 | /* ret=ZSendNotice(¬ice, ZAUTH); */ |
---|
| 419 | ret=ZSrvSendNotice(¬ice, ZAUTH, send_zephyr_helper); |
---|
| 420 | |
---|
| 421 | /* free then check the return */ |
---|
| 422 | owl_free(notice.z_message); |
---|
| 423 | ZFreeNotice(¬ice); |
---|
| 424 | if (ret!=ZERR_NONE) { |
---|
[ec6ff52] | 425 | owl_function_error("Error sending zephyr"); |
---|
[7d4fbcd] | 426 | return(ret); |
---|
| 427 | } |
---|
| 428 | return(0); |
---|
[be0a79f] | 429 | #else |
---|
| 430 | return(0); |
---|
| 431 | #endif |
---|
[7d4fbcd] | 432 | } |
---|
| 433 | |
---|
[be0a79f] | 434 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 435 | Code_t send_zephyr_helper(ZNotice_t *notice, char *buf, int len, int wait) |
---|
| 436 | { |
---|
[7d4fbcd] | 437 | return(ZSendPacket(buf, len, 0)); |
---|
| 438 | } |
---|
[be0a79f] | 439 | #endif |
---|
[7d4fbcd] | 440 | |
---|
[31e48a3] | 441 | void send_ping(char *to) |
---|
| 442 | { |
---|
[be0a79f] | 443 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 444 | send_zephyr("PING", "", "MESSAGE", "PERSONAL", to, ""); |
---|
[be0a79f] | 445 | #endif |
---|
[7d4fbcd] | 446 | } |
---|
| 447 | |
---|
[be0a79f] | 448 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 449 | void owl_zephyr_handle_ack(ZNotice_t *retnotice) |
---|
| 450 | { |
---|
[7d4fbcd] | 451 | char *tmp; |
---|
| 452 | |
---|
| 453 | /* if it's an HMACK ignore it */ |
---|
| 454 | if (retnotice->z_kind == HMACK) return; |
---|
[aecf3e6] | 455 | |
---|
[7d4fbcd] | 456 | if (retnotice->z_kind == SERVNAK) { |
---|
[ec6ff52] | 457 | owl_function_error("Authorization failure sending zephyr"); |
---|
[7d4fbcd] | 458 | } else if ((retnotice->z_kind != SERVACK) || !retnotice->z_message_len) { |
---|
[ec6ff52] | 459 | owl_function_error("Detected server failure while receiving acknowledgement"); |
---|
[7d4fbcd] | 460 | } else if (!strcmp(retnotice->z_message, ZSRVACK_SENT)) { |
---|
| 461 | if (!strcasecmp(retnotice->z_opcode, "ping")) { |
---|
| 462 | return; |
---|
| 463 | } else if (!strcasecmp(retnotice->z_class, "message") && |
---|
| 464 | !strcasecmp(retnotice->z_class_inst, "personal")) { |
---|
[4b464a4] | 465 | tmp=short_zuser(retnotice->z_recipient); |
---|
[b4db911] | 466 | owl_function_makemsg("Message sent to %s.", tmp); |
---|
[7d4fbcd] | 467 | free(tmp); |
---|
| 468 | } else { |
---|
[b4db911] | 469 | owl_function_makemsg("Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst); |
---|
[7d4fbcd] | 470 | } |
---|
| 471 | } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) { |
---|
| 472 | if (strcasecmp(retnotice->z_class, "message")) { |
---|
[9119a47] | 473 | char buff[1024]; |
---|
[269ed34] | 474 | owl_function_error("No one subscribed to class class %s", retnotice->z_class); |
---|
| 475 | sprintf(buff, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class); |
---|
[9119a47] | 476 | owl_function_adminmsg("", buff); |
---|
[7d4fbcd] | 477 | } else { |
---|
[9119a47] | 478 | char buff[1024]; |
---|
[4b464a4] | 479 | tmp = short_zuser(retnotice->z_recipient); |
---|
[ec6ff52] | 480 | owl_function_error("%s: Not logged in or subscribing to messages.", |
---|
[1c6c4d3] | 481 | tmp); |
---|
[9119a47] | 482 | |
---|
| 483 | sprintf(buff, "Could not send message to %s: not logged in or subscribing to messages.\n", tmp); |
---|
| 484 | owl_function_adminmsg("", buff); |
---|
[2b86d14] | 485 | if (owl_global_is_logging(&g)) owl_log_outgoing_zephyr_error(tmp, buff); |
---|
[1c6c4d3] | 486 | owl_free(tmp); |
---|
[7d4fbcd] | 487 | } |
---|
| 488 | } else { |
---|
[ec6ff52] | 489 | owl_function_error("Internal error on ack (%s)", retnotice->z_message); |
---|
[7d4fbcd] | 490 | } |
---|
| 491 | } |
---|
[09489b89] | 492 | #else |
---|
| 493 | void owl_zephyr_handle_ack(void *retnotice) |
---|
| 494 | { |
---|
| 495 | } |
---|
[be0a79f] | 496 | #endif |
---|
[7d4fbcd] | 497 | |
---|
[be0a79f] | 498 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 499 | int owl_zephyr_notice_is_ack(ZNotice_t *n) |
---|
| 500 | { |
---|
[7d4fbcd] | 501 | if (n->z_kind == SERVNAK || n->z_kind == SERVACK || n->z_kind == HMACK) { |
---|
| 502 | if (!strcasecmp(n->z_class, LOGIN_CLASS)) return(0); |
---|
| 503 | return(1); |
---|
| 504 | } |
---|
| 505 | return(0); |
---|
| 506 | } |
---|
[09489b89] | 507 | #else |
---|
| 508 | int owl_zephyr_notice_is_ack(void *n) |
---|
| 509 | { |
---|
| 510 | return(0); |
---|
| 511 | } |
---|
[be0a79f] | 512 | #endif |
---|
[7d4fbcd] | 513 | |
---|
[31e48a3] | 514 | void owl_zephyr_zaway(owl_message *m) |
---|
| 515 | { |
---|
[be0a79f] | 516 | #ifdef HAVE_LIBZEPHYR |
---|
[7c8060d0] | 517 | char *tmpbuff, *myuser, *to; |
---|
[7d4fbcd] | 518 | |
---|
[aa2f6364] | 519 | /* bail if it doesn't look like a message we should reply to. Some |
---|
[2de4f20] | 520 | * of this defined by the way zaway(1) works |
---|
| 521 | */ |
---|
[7d4fbcd] | 522 | if (strcasecmp(owl_message_get_class(m), "message")) return; |
---|
| 523 | if (strcasecmp(owl_message_get_recipient(m), ZGetSender())) return; |
---|
| 524 | if (!strcasecmp(owl_message_get_sender(m), "")) return; |
---|
| 525 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) return; |
---|
| 526 | if (!strcasecmp(owl_message_get_opcode(m), "auto")) return; |
---|
[d023c25] | 527 | if (!strcasecmp(owl_message_get_zsig(m), "Automated reply:")) return; |
---|
[7d4fbcd] | 528 | if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) return; |
---|
[9854278] | 529 | if (owl_message_get_attribute_value(m, "isauto")) return; |
---|
[7d4fbcd] | 530 | |
---|
[7c8060d0] | 531 | if (owl_global_is_smartstrip(&g)) { |
---|
[e3d9c77] | 532 | to=owl_zephyr_smartstripped_user(owl_message_get_sender(m)); |
---|
[7c8060d0] | 533 | } else { |
---|
| 534 | to=owl_strdup(owl_message_get_sender(m)); |
---|
| 535 | } |
---|
| 536 | |
---|
[7d4fbcd] | 537 | send_zephyr("", |
---|
| 538 | "Automated reply:", |
---|
| 539 | owl_message_get_class(m), |
---|
| 540 | owl_message_get_instance(m), |
---|
[7c8060d0] | 541 | to, |
---|
[7d4fbcd] | 542 | owl_global_get_zaway_msg(&g)); |
---|
| 543 | |
---|
[7c8060d0] | 544 | myuser=short_zuser(to); |
---|
[aa2f6364] | 545 | if (!strcasecmp(owl_message_get_instance(m), "personal")) { |
---|
| 546 | tmpbuff = owl_sprintf("zwrite %s", myuser); |
---|
| 547 | } else { |
---|
| 548 | tmpbuff = owl_sprintf("zwrite -i %s %s", owl_message_get_instance(m), myuser); |
---|
| 549 | } |
---|
| 550 | owl_free(myuser); |
---|
[7c8060d0] | 551 | owl_free(to); |
---|
[aa2f6364] | 552 | |
---|
[7d4fbcd] | 553 | /* display the message as an admin message in the receive window */ |
---|
[d023c25] | 554 | owl_function_make_outgoing_zephyr(owl_global_get_zaway_msg(&g), tmpbuff, "Automated reply:"); |
---|
[7d4fbcd] | 555 | owl_free(tmpbuff); |
---|
[be0a79f] | 556 | #endif |
---|
[7d4fbcd] | 557 | } |
---|
| 558 | |
---|
[be0a79f] | 559 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 560 | void owl_zephyr_hackaway_cr(ZNotice_t *n) |
---|
| 561 | { |
---|
[7d4fbcd] | 562 | /* replace \r's with ' '. Gross-ish */ |
---|
| 563 | int i; |
---|
| 564 | |
---|
| 565 | for (i=0; i<n->z_message_len; i++) { |
---|
| 566 | if (n->z_message[i]=='\r') { |
---|
| 567 | n->z_message[i]=' '; |
---|
| 568 | } |
---|
| 569 | } |
---|
| 570 | } |
---|
[be0a79f] | 571 | #endif |
---|
[7d4fbcd] | 572 | |
---|
[31e48a3] | 573 | void owl_zephyr_zlocate(char *user, char *out, int auth) |
---|
| 574 | { |
---|
[be0a79f] | 575 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 576 | int ret, numlocs; |
---|
| 577 | int one = 1; |
---|
| 578 | ZLocations_t locations; |
---|
| 579 | char *myuser; |
---|
| 580 | |
---|
| 581 | strcpy(out, ""); |
---|
[8262340] | 582 | ZResetAuthentication(); |
---|
[7d4fbcd] | 583 | ret=ZLocateUser(user,&numlocs,auth?ZAUTH:ZNOAUTH); |
---|
| 584 | if (ret != ZERR_NONE) { |
---|
[667a1b6] | 585 | sprintf(out, "Error locating user %s\n", user); |
---|
| 586 | return; |
---|
[7d4fbcd] | 587 | } |
---|
| 588 | |
---|
| 589 | if (numlocs==0) { |
---|
[2527615] | 590 | myuser=short_zuser(user); |
---|
| 591 | sprintf(out, "%s: Hidden or not logged-in\n", myuser); |
---|
| 592 | owl_free(myuser); |
---|
[7d4fbcd] | 593 | return; |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | for (;numlocs;numlocs--) { |
---|
| 597 | ZGetLocations(&locations,&one); |
---|
[4b464a4] | 598 | myuser=short_zuser(user); |
---|
[667a1b6] | 599 | sprintf(out, "%s%s: %s\t%s\t%s\n", out, myuser, |
---|
| 600 | locations.host ? locations.host : "?", |
---|
| 601 | locations.tty ? locations.tty : "?", |
---|
| 602 | locations.time ? locations.time : "?"); |
---|
[7d4fbcd] | 603 | owl_free(myuser); |
---|
| 604 | } |
---|
[be0a79f] | 605 | #endif |
---|
[7d4fbcd] | 606 | } |
---|
[bde7714] | 607 | |
---|
[31e48a3] | 608 | void owl_zephyr_addsub(char *filename, char *class, char *inst, char *recip) |
---|
| 609 | { |
---|
[be0a79f] | 610 | #ifdef HAVE_LIBZEPHYR |
---|
[bde7714] | 611 | char *line, subsfile[LINE], buff[LINE]; |
---|
| 612 | FILE *file; |
---|
| 613 | |
---|
| 614 | line=owl_zephyr_makesubline(class, inst, recip); |
---|
| 615 | |
---|
| 616 | if (filename==NULL) { |
---|
| 617 | sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs"); |
---|
| 618 | } else { |
---|
| 619 | strcpy(subsfile, filename); |
---|
| 620 | } |
---|
| 621 | |
---|
[74037d9] | 622 | /* if the file already exists, check to see if the sub is already there */ |
---|
[bde7714] | 623 | file=fopen(subsfile, "r"); |
---|
[74037d9] | 624 | if (file) { |
---|
| 625 | while (fgets(buff, LINE, file)!=NULL) { |
---|
| 626 | if (!strcasecmp(buff, line)) { |
---|
| 627 | owl_function_error("Subscription already present in %s", subsfile); |
---|
| 628 | owl_free(line); |
---|
| 629 | return; |
---|
| 630 | } |
---|
[bde7714] | 631 | } |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /* if we get here then we didn't find it */ |
---|
| 635 | fclose(file); |
---|
| 636 | file=fopen(subsfile, "a"); |
---|
| 637 | if (!file) { |
---|
[ec6ff52] | 638 | owl_function_error("Error opening file %s for writing", subsfile); |
---|
[bde7714] | 639 | owl_free(line); |
---|
| 640 | return; |
---|
| 641 | } |
---|
| 642 | fputs(line, file); |
---|
| 643 | fclose(file); |
---|
| 644 | owl_function_makemsg("Subscription added"); |
---|
| 645 | |
---|
| 646 | owl_free(line); |
---|
[be0a79f] | 647 | #endif |
---|
[bde7714] | 648 | } |
---|
| 649 | |
---|
[31e48a3] | 650 | void owl_zephyr_delsub(char *filename, char *class, char *inst, char *recip) |
---|
| 651 | { |
---|
[be0a79f] | 652 | #ifdef HAVE_LIBZEPHYR |
---|
[b2a91b6] | 653 | char *line, *subsfile; |
---|
[bde7714] | 654 | |
---|
| 655 | line=owl_zephyr_makesubline(class, inst, recip); |
---|
[b2a91b6] | 656 | line[strlen(line)-1]='\0'; |
---|
[bde7714] | 657 | |
---|
[b2a91b6] | 658 | if (!filename) { |
---|
| 659 | subsfile=owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); |
---|
[bde7714] | 660 | } else { |
---|
[b2a91b6] | 661 | subsfile=owl_strdup(filename); |
---|
[bde7714] | 662 | } |
---|
[b2a91b6] | 663 | |
---|
| 664 | owl_util_file_deleteline(subsfile, line, 1); |
---|
| 665 | owl_free(subsfile); |
---|
[bde7714] | 666 | owl_free(line); |
---|
| 667 | owl_function_makemsg("Subscription removed"); |
---|
[be0a79f] | 668 | #endif |
---|
[bde7714] | 669 | } |
---|
| 670 | |
---|
[b2a91b6] | 671 | /* caller must free the return */ |
---|
[31e48a3] | 672 | char *owl_zephyr_makesubline(char *class, char *inst, char *recip) |
---|
| 673 | { |
---|
[bde7714] | 674 | char *out; |
---|
| 675 | |
---|
| 676 | out=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+30); |
---|
| 677 | sprintf(out, "%s,%s,%s\n", class, inst, !strcmp(recip, "") ? "*" : recip); |
---|
| 678 | return(out); |
---|
| 679 | } |
---|
[31e48a3] | 680 | |
---|
| 681 | |
---|
| 682 | void owl_zephyr_zlog_in(void) |
---|
| 683 | { |
---|
[be0a79f] | 684 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 685 | char *exposure, *eset; |
---|
| 686 | int ret; |
---|
| 687 | |
---|
| 688 | ZResetAuthentication(); |
---|
| 689 | |
---|
| 690 | eset=EXPOSE_REALMVIS; |
---|
| 691 | exposure=ZGetVariable("exposure"); |
---|
| 692 | if (exposure==NULL) { |
---|
| 693 | eset=EXPOSE_REALMVIS; |
---|
| 694 | } else if (!strcasecmp(exposure,EXPOSE_NONE)) { |
---|
| 695 | eset = EXPOSE_NONE; |
---|
| 696 | } else if (!strcasecmp(exposure,EXPOSE_OPSTAFF)) { |
---|
| 697 | eset = EXPOSE_OPSTAFF; |
---|
| 698 | } else if (!strcasecmp(exposure,EXPOSE_REALMVIS)) { |
---|
| 699 | eset = EXPOSE_REALMVIS; |
---|
| 700 | } else if (!strcasecmp(exposure,EXPOSE_REALMANN)) { |
---|
| 701 | eset = EXPOSE_REALMANN; |
---|
| 702 | } else if (!strcasecmp(exposure,EXPOSE_NETVIS)) { |
---|
| 703 | eset = EXPOSE_NETVIS; |
---|
| 704 | } else if (!strcasecmp(exposure,EXPOSE_NETANN)) { |
---|
| 705 | eset = EXPOSE_NETANN; |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | ret=ZSetLocation(eset); |
---|
| 709 | if (ret != ZERR_NONE) { |
---|
| 710 | /* |
---|
| 711 | char buff[LINE]; |
---|
| 712 | sprintf(buff, "Error setting location: %s", error_message(ret)); |
---|
| 713 | owl_function_makemsg(buff); |
---|
| 714 | */ |
---|
| 715 | } |
---|
[be0a79f] | 716 | #endif |
---|
[31e48a3] | 717 | } |
---|
| 718 | |
---|
| 719 | void owl_zephyr_zlog_out(void) |
---|
| 720 | { |
---|
[be0a79f] | 721 | #ifdef HAVE_LIBZEPHYR |
---|
[31e48a3] | 722 | int ret; |
---|
| 723 | |
---|
| 724 | ZResetAuthentication(); |
---|
| 725 | ret=ZUnsetLocation(); |
---|
| 726 | if (ret != ZERR_NONE) { |
---|
| 727 | /* |
---|
| 728 | char buff[LINE]; |
---|
| 729 | sprintf(buff, "Error unsetting location: %s", error_message(ret)); |
---|
| 730 | owl_function_makemsg(buff); |
---|
| 731 | */ |
---|
| 732 | } |
---|
[be0a79f] | 733 | #endif |
---|
[31e48a3] | 734 | } |
---|
| 735 | |
---|
[65ad073] | 736 | void owl_zephyr_addbuddy(char *name) |
---|
| 737 | { |
---|
| 738 | char *filename; |
---|
| 739 | FILE *file; |
---|
| 740 | |
---|
| 741 | filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); |
---|
| 742 | file=fopen(filename, "a"); |
---|
| 743 | owl_free(filename); |
---|
| 744 | if (!file) { |
---|
[ec6ff52] | 745 | owl_function_error("Error opening zephyr buddy file for append"); |
---|
[65ad073] | 746 | return; |
---|
| 747 | } |
---|
| 748 | fprintf(file, "%s\n", name); |
---|
| 749 | fclose(file); |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | void owl_zephyr_delbuddy(char *name) |
---|
| 753 | { |
---|
| 754 | char *filename; |
---|
| 755 | |
---|
| 756 | filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); |
---|
| 757 | owl_util_file_deleteline(filename, name, 0); |
---|
| 758 | owl_free(filename); |
---|
| 759 | } |
---|
[9381782] | 760 | |
---|
| 761 | /* return auth string */ |
---|
[09489b89] | 762 | #ifdef HAVE_LIBZEPHYR |
---|
[9381782] | 763 | char *owl_zephyr_get_authstr(ZNotice_t *n) |
---|
| 764 | { |
---|
| 765 | |
---|
| 766 | if (!n) return("UNKNOWN"); |
---|
| 767 | |
---|
| 768 | if (n->z_auth == ZAUTH_FAILED) { |
---|
| 769 | return ("FAILED"); |
---|
| 770 | } else if (n->z_auth == ZAUTH_NO) { |
---|
| 771 | return ("NO"); |
---|
| 772 | } else if (n->z_auth == ZAUTH_YES) { |
---|
| 773 | return ("YES"); |
---|
| 774 | } else { |
---|
| 775 | return ("UNKNOWN"); |
---|
| 776 | } |
---|
| 777 | } |
---|
[09489b89] | 778 | #else |
---|
| 779 | char *owl_zephyr_get_authstr(void *n) |
---|
| 780 | { |
---|
| 781 | return(""); |
---|
| 782 | } |
---|
| 783 | #endif |
---|
[9381782] | 784 | |
---|
[2de4f20] | 785 | /* Returns a buffer of subscriptions or an error message. Caller must |
---|
| 786 | * free the return. |
---|
[09489b89] | 787 | */ |
---|
| 788 | char *owl_zephyr_getsubs() |
---|
| 789 | { |
---|
| 790 | #ifdef HAVE_LIBZEPHYR |
---|
| 791 | int ret, num, i, one; |
---|
| 792 | ZSubscription_t sub; |
---|
| 793 | char *out, *tmpbuff; |
---|
| 794 | one=1; |
---|
| 795 | |
---|
| 796 | ret=ZRetrieveSubscriptions(0, &num); |
---|
| 797 | if (ret==ZERR_TOOMANYSUBS) { |
---|
[c8735aa] | 798 | return(owl_strdup("Zephyr: too many subscriptions\n")); |
---|
| 799 | } else if (ret) { |
---|
| 800 | return(owl_strdup("Zephyr: error retriving subscriptions\n")); |
---|
[09489b89] | 801 | } |
---|
| 802 | |
---|
| 803 | out=owl_malloc(num*500); |
---|
| 804 | tmpbuff=owl_malloc(num*500); |
---|
| 805 | strcpy(out, ""); |
---|
| 806 | for (i=0; i<num; i++) { |
---|
| 807 | if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) { |
---|
| 808 | owl_free(out); |
---|
| 809 | owl_free(tmpbuff); |
---|
| 810 | ZFlushSubscriptions(); |
---|
| 811 | out=owl_strdup("Error while getting subscriptions\n"); |
---|
| 812 | return(out); |
---|
| 813 | } else { |
---|
[03955f3] | 814 | sprintf(tmpbuff, "<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out); |
---|
[09489b89] | 815 | strcpy(out, tmpbuff); |
---|
| 816 | } |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | owl_free(tmpbuff); |
---|
| 820 | ZFlushSubscriptions(); |
---|
| 821 | return(out); |
---|
| 822 | #else |
---|
[12c35df] | 823 | return(owl_strdup("Zephyr not available")); |
---|
[09489b89] | 824 | #endif |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | char *owl_zephyr_get_variable(char *var) |
---|
| 828 | { |
---|
| 829 | #ifdef HAVE_LIBZEPHYR |
---|
| 830 | return(ZGetVariable(var)); |
---|
| 831 | #else |
---|
| 832 | return(""); |
---|
| 833 | #endif |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | void owl_zephyr_set_locationinfo(char *host, char *val) |
---|
| 837 | { |
---|
| 838 | #ifdef HAVE_LIBZEPHYR |
---|
| 839 | ZInitLocationInfo(host, val); |
---|
| 840 | #endif |
---|
| 841 | } |
---|
| 842 | |
---|
[e3d9c77] | 843 | /* Strip a local realm fron the zephyr user name. |
---|
| 844 | * The caller must free the return |
---|
| 845 | */ |
---|
| 846 | char *short_zuser(char *in) |
---|
| 847 | { |
---|
| 848 | char *out, *ptr; |
---|
| 849 | |
---|
| 850 | out=owl_strdup(in); |
---|
| 851 | ptr=strchr(out, '@'); |
---|
| 852 | if (ptr) { |
---|
| 853 | if (!strcasecmp(ptr+1, owl_zephyr_get_realm())) { |
---|
| 854 | *ptr='\0'; |
---|
| 855 | } |
---|
| 856 | } |
---|
| 857 | return(out); |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | /* Append a local realm to the zephyr user name if necessary. |
---|
| 861 | * The caller must free the return. |
---|
| 862 | */ |
---|
| 863 | char *long_zuser(char *in) |
---|
| 864 | { |
---|
[1971b59] | 865 | if (strchr(in, '@')) { |
---|
| 866 | return(owl_strdup(in)); |
---|
[e3d9c77] | 867 | } |
---|
[1971b59] | 868 | return(owl_sprintf("%s@%s", in, owl_zephyr_get_realm())); |
---|
[e3d9c77] | 869 | } |
---|
| 870 | |
---|
| 871 | /* strip out the instance from a zsender's principal. Preserves the |
---|
| 872 | * realm if present. daemon.webzephyr is a special case. The |
---|
| 873 | * caller must free the return |
---|
| 874 | */ |
---|
| 875 | char *owl_zephyr_smartstripped_user(char *in) |
---|
| 876 | { |
---|
| 877 | char *ptr, *realm, *out; |
---|
| 878 | |
---|
| 879 | out=owl_strdup(in); |
---|
| 880 | |
---|
| 881 | /* bail immeaditly if we don't have to do any work */ |
---|
| 882 | ptr=strchr(in, '.'); |
---|
| 883 | if (!strchr(in, '/') && !ptr) { |
---|
| 884 | /* no '/' and no '.' */ |
---|
| 885 | return(out); |
---|
| 886 | } |
---|
| 887 | if (ptr && strchr(in, '@') && (ptr > strchr(in, '@'))) { |
---|
| 888 | /* There's a '.' but it's in the realm */ |
---|
| 889 | return(out); |
---|
| 890 | } |
---|
| 891 | if (!strncasecmp(in, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PRINCIPAL))) { |
---|
| 892 | return(out); |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | /* remove the realm from ptr, but hold on to it */ |
---|
| 896 | realm=strchr(out, '@'); |
---|
| 897 | if (realm) realm[0]='\0'; |
---|
| 898 | |
---|
| 899 | /* strip */ |
---|
| 900 | ptr=strchr(out, '.'); |
---|
| 901 | if (!ptr) ptr=strchr(out, '/'); |
---|
| 902 | ptr[0]='\0'; |
---|
| 903 | |
---|
| 904 | /* reattach the realm if we had one */ |
---|
| 905 | if (realm) { |
---|
| 906 | strcat(out, "@"); |
---|
| 907 | strcat(out, realm+1); |
---|
| 908 | } |
---|
| 909 | |
---|
| 910 | return(out); |
---|
| 911 | } |
---|
[5a95b69] | 912 | |
---|
| 913 | /* read the list of users in 'filename' as a .anyone file, and put the |
---|
| 914 | * names of the zephyr users in the list 'in'. If 'filename' is NULL, |
---|
| 915 | * use the default .anyone file in the users home directory. Returns |
---|
| 916 | * -1 on failure, 0 on success. |
---|
| 917 | */ |
---|
| 918 | int owl_zephyr_get_anyone_list(owl_list *in, char *filename) |
---|
| 919 | { |
---|
| 920 | #ifdef HAVE_LIBZEPHYR |
---|
| 921 | char *ourfile, *tmp, buff[LINE]; |
---|
| 922 | FILE *f; |
---|
| 923 | |
---|
| 924 | if (filename==NULL) { |
---|
| 925 | tmp=owl_global_get_homedir(&g); |
---|
| 926 | ourfile=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); |
---|
| 927 | } else { |
---|
| 928 | ourfile=owl_strdup(filename); |
---|
| 929 | } |
---|
| 930 | |
---|
| 931 | f=fopen(ourfile, "r"); |
---|
| 932 | if (!f) { |
---|
| 933 | owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : ""); |
---|
| 934 | owl_free(ourfile); |
---|
| 935 | return(-1); |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | while (fgets(buff, LINE, f)!=NULL) { |
---|
| 939 | /* ignore comments, blank lines etc. */ |
---|
| 940 | if (buff[0]=='#') continue; |
---|
| 941 | if (buff[0]=='\n') continue; |
---|
| 942 | if (buff[0]=='\0') continue; |
---|
| 943 | |
---|
| 944 | /* strip the \n */ |
---|
| 945 | buff[strlen(buff)-1]='\0'; |
---|
| 946 | |
---|
| 947 | /* ingore from # on */ |
---|
| 948 | tmp=strchr(buff, '#'); |
---|
| 949 | if (tmp) tmp[0]='\0'; |
---|
| 950 | |
---|
| 951 | /* ingore from SPC */ |
---|
| 952 | tmp=strchr(buff, ' '); |
---|
| 953 | if (tmp) tmp[0]='\0'; |
---|
| 954 | |
---|
| 955 | /* stick on the local realm. */ |
---|
| 956 | if (!strchr(buff, '@')) { |
---|
| 957 | strcat(buff, "@"); |
---|
| 958 | strcat(buff, ZGetRealm()); |
---|
| 959 | } |
---|
| 960 | owl_list_append_element(in, owl_strdup(buff)); |
---|
| 961 | } |
---|
| 962 | fclose(f); |
---|
| 963 | owl_free(ourfile); |
---|
| 964 | return(0); |
---|
| 965 | #else |
---|
| 966 | return(-1); |
---|
| 967 | #endif |
---|
| 968 | } |
---|