Changeset 1d2125a in code
- Timestamp:
- Mar 2, 2014, 1:50:57 AM (11 years ago)
- Branches:
- master
- Children:
- 59a7416
- Parents:
- d554223
- git-author:
- Mike Belopuhov <mike@…> (03/02/14 01:48:34)
- git-committer:
- Mike Belopuhov <mike@…> (03/02/14 01:50:57)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
icb.c
rd554223 r1d2125a 35 35 void icb_login(struct icb_session *, char *, char *, char *); 36 36 int icb_dowho(struct icb_session *, struct icb_group *); 37 int icb_modpermit(struct icb_session *); 37 38 char *icb_nextfield(char **); 38 39 … … 518 519 519 520 /* 521 * icb_modpermit: checks user against the moderators table if it has 522 * been populated 523 */ 524 int 525 icb_modpermit(struct icb_session *is) 526 { 527 extern char modtab[ICB_MTABLEN][ICB_MAXNICKLEN]; 528 extern int modtabcnt; 529 530 if (modtabcnt == 0 || 531 bsearch(is->nick, modtab, modtabcnt, ICB_MAXNICKLEN, 532 (int (*)(const void *, const void *))strcmp)) 533 return (1); 534 return (0); 535 } 536 537 /* 520 538 * icb_pass: passes moderation of group "ig" from "from" to "to", 521 539 * returns -1 if "from" is not a moderator, 1 if passed … … 530 548 return (-1); 531 549 if (!from && !to) 550 return (-1); 551 if (to && !icb_modpermit(to)) 532 552 return (-1); 533 553 ig->mod = to; -
icb.h
rd554223 r1d2125a 23 23 #define ICB_MAXPASSLEN 32 24 24 #define ICB_MAXTOPICLEN 160 25 #define ICB_MTABLEN 50 /* XXX */ 25 26 26 27 #define ICB_M_LOGIN 'a' … … 120 121 void icb_input(struct icb_session *); 121 122 int icb_ismod(struct icb_group *, struct icb_session *); 123 int icb_modpermit(struct icb_session *); 122 124 int icb_pass(struct icb_group *, struct icb_session *, struct icb_session *); 123 125 void icb_privmsg(struct icb_session *, char *, char *); -
icbd.c
rd554223 r1d2125a 44 44 extern char *__progname; 45 45 46 char modtab[ICB_MTABLEN][ICB_MAXNICKLEN]; 47 int modtabcnt; 46 48 char srvname[MAXHOSTNAMELEN]; 47 49 int creategroups; … … 57 59 void icbd_log(struct icb_session *, int, const char *, ...); 58 60 void icbd_grplist(char *); 61 void icbd_modtab(char *); 59 62 void icbd_restrict(void); 60 63 void icbd_write(struct icb_session *, char *, ssize_t); … … 71 74 icb_init(&ic); 72 75 73 while ((ch = getopt(argc, argv, "46CdG: S:v")) != -1)76 while ((ch = getopt(argc, argv, "46CdG:M:S:v")) != -1) 74 77 switch (ch) { 75 78 case '4': … … 87 90 case 'G': 88 91 icbd_grplist(optarg); 92 break; 93 case 'M': 94 icbd_modtab(optarg); 89 95 break; 90 96 case 'S': … … 276 282 { 277 283 (void)fprintf(stderr, "usage: %s [-46Cdv] [-G group1[,group2,...]] " 278 "[- S name] [[addr][:port] ...]\n", __progname);284 "[-M modtab]\n\t[-S name] [[addr][:port] ...]\n", __progname); 279 285 exit(EX_USAGE); 280 286 } … … 455 461 } 456 462 463 void 464 icbd_modtab(char *mtab) 465 { 466 FILE *fp; 467 char *buf, *lbuf; 468 size_t len; 469 470 if ((fp = fopen(mtab, "r")) == NULL) 471 err(EX_NOINPUT, "%s", mtab); 472 473 bzero(modtab, ICB_MTABLEN * ICB_MAXNICKLEN); 474 lbuf = NULL; 475 while ((buf = fgetln(fp, &len)) && modtabcnt < ICB_MTABLEN) { 476 if (buf[len - 1] == '\n') 477 buf[len - 1] = '\0'; 478 else { 479 /* EOF without EOL, copy and add the NUL */ 480 if ((lbuf = malloc(len + 1)) == NULL) 481 err(1, NULL); 482 memcpy(lbuf, buf, len); 483 lbuf[len] = '\0'; 484 buf = lbuf; 485 } 486 while (buf[0] == ' ' || buf[0] == '\t') 487 buf++; 488 if (buf[0] == '#' || buf[0] == '\0') 489 continue; 490 strlcpy(modtab[modtabcnt++], buf, ICB_MAXNICKLEN); 491 } 492 free(lbuf); 493 494 qsort(modtab, modtabcnt, ICB_MAXNICKLEN, 495 (int (*)(const void *, const void *))strcmp); 496 497 fclose(fp); 498 } 499 457 500 time_t 458 501 getmonotime(void)
Note:
See TracChangeset
for help on using the changeset viewer.