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