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