Changeset 677a45b in code
- Timestamp:
- Apr 22, 2015, 5:28:48 PM (10 years ago)
- Branches:
- master
- Children:
- 176b6ef
- Parents:
- 5dfeb4c
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cmd.c
r5dfeb4c r677a45b 177 177 return; 178 178 } else { 179 if ((ig = icb_addgroup(is, group , NULL)) == NULL) {179 if ((ig = icb_addgroup(is, group)) == NULL) { 180 180 icb_error(is, "Can't create group"); 181 181 return; -
icb.c
r5dfeb4c r677a45b 168 168 return (1); 169 169 } else { 170 if ((ig = icb_addgroup(is, group , NULL)) == NULL) {170 if ((ig = icb_addgroup(is, group)) == NULL) { 171 171 icb_error(is, "Can't create group %s", group); 172 172 return (0); … … 441 441 */ 442 442 struct icb_group * 443 icb_addgroup(struct icb_session *is, char *name , char *mpass)443 icb_addgroup(struct icb_session *is, char *name) 444 444 { 445 445 struct icb_group *ig; … … 448 448 return (NULL); 449 449 strlcpy(ig->name, name, sizeof ig->name); 450 if (mpass)451 strlcpy(ig->mpass, mpass, sizeof ig->mpass);452 450 if (is) 453 451 ig->mod = is; … … 628 626 629 627 /* 628 * icb_token: copies a sequence of characters delimited by the 'sep' character 629 * from the source buffer 'buf' at offset indicated by 'bufptr' to 630 * the destination buffer 'dst' and sets 'bufptr' to the next byte 631 * after 'sep'. 632 */ 633 int 634 icb_token(char *buf, int len, char **bufptr, char *dst, int dlen, int sep) 635 { 636 char *start; 637 int i, ret; 638 639 if (buf == NULL || len <= 0 || dlen <= 0) 640 return (0); 641 if (*bufptr == NULL) 642 *bufptr = buf; 643 start = *bufptr; 644 for (i = *bufptr - buf; i < len; i++, (*bufptr)++) { 645 if (**bufptr == sep || **bufptr == '\0') { 646 /* copy and null terminate the token */ 647 ret = strlcpy(dst, start, 648 MIN(*bufptr - start + 1, dlen)); 649 if (**bufptr != '\0') 650 (*bufptr)++; 651 return (ret); 652 } 653 } 654 /* 655 * Reached the end of the buffer without finding a field separator 656 * nor the end of line character. If we have advanced our pointer 657 * we should copy the resulting single field out. 658 */ 659 if (*bufptr - start > 0) { 660 ret = strlcpy(dst, start, MIN(*bufptr - start + 1, dlen)); 661 return (ret); 662 } 663 return (0); 664 } 665 666 /* 630 667 * icb_vis: strnvis-like function that escapes percentages as well 631 668 */ -
icb.h
r5dfeb4c r677a45b 28 28 #define ICB_MAXGRPLEN 32 29 29 #define ICB_MAXNICKLEN 32 30 #define ICB_MAXPASSLEN 3231 30 #define ICB_MAXTOPICLEN 160 32 31 #define ICB_MAXHOSTLEN 40 … … 107 106 struct icb_group { 108 107 char name[ICB_MAXGRPLEN]; 109 char mpass[ICB_MAXPASSLEN];110 108 char topic[ICB_MAXTOPICLEN]; 111 109 LIST_ENTRY(icb_group) entry; … … 125 123 /* icb.c */ 126 124 struct icb_group * 127 icb_addgroup(struct icb_session *, char * , char *);125 icb_addgroup(struct icb_session *, char *); 128 126 void icb_cmdout(struct icb_session *, int, char *); 129 127 void icb_delgroup(struct icb_group *); … … 143 141 int, const char *, ...); 144 142 void icb_who(struct icb_session *, struct icb_group *); 143 int icb_token(char *, int, char **, char *, int, int); 145 144 int icb_vis(char *, const char *, size_t, int); -
icbd.c
r5dfeb4c r677a45b 65 65 void icbd_dispatch(struct bufferevent *, void *); 66 66 void icbd_log(struct icb_session *, int, const char *, ...); 67 void icbd_grplist(char *);68 67 void icbd_restrict(void); 69 68 void icbd_send(struct icb_session *, char *, ssize_t); … … 79 78 int ch, nsocks = 0, save_errno = 0; 80 79 int inet4 = 0, inet6 = 0; 80 char group[ICB_MAXGRPLEN], *grplist = NULL; 81 char *ptr = NULL; 81 82 82 83 /* init group lists before calling icb_addgroup */ … … 98 99 break; 99 100 case 'G': 100 icbd_grplist(optarg);101 grplist = optarg; 101 102 break; 102 103 case 'L': … … 124 125 125 126 /* add group "1" as it's a login group for most of the clients */ 126 if (icb_addgroup(NULL, "1" , NULL) == NULL)127 if (icb_addgroup(NULL, "1") == NULL) 127 128 err(EX_UNAVAILABLE, NULL); 129 130 if (grplist) { 131 while (icb_token(grplist, strlen(grplist), &ptr, group, 132 ICB_MAXGRPLEN, ',') > 0) 133 if (icb_addgroup(NULL, group) == NULL) 134 err(EX_UNAVAILABLE, NULL); 135 } 128 136 129 137 if (argc == 0) … … 492 500 493 501 void 494 icbd_grplist(char *list)495 {496 char *s, *s1, *s2;497 int last = 0;498 499 if (!list || strlen(list) == 0)500 return;501 502 /* "group1[:pass1][,group2[:pass2],...]" */503 s = list;504 s1 = s2 = NULL;505 while (!last && s) {506 if ((s1 = strchr(s, ',')) != NULL)507 *s1 = '\0';508 else {509 last = 1;510 s1 = s;511 }512 if ((s2 = strchr(s, ':')) != NULL)513 *s2 = '\0';514 if (icb_addgroup(NULL, s, s2 ? ++s2 : NULL) == NULL)515 err(EX_UNAVAILABLE, NULL);516 s = ++s1;517 s1 = s2 = NULL;518 }519 }520 521 void522 502 icbd_modupdate(void) 523 503 {
Note:
See TracChangeset
for help on using the changeset viewer.