Changeset 677a45b in code


Ignore:
Timestamp:
Apr 22, 2015, 5:28:48 PM (10 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
176b6ef
Parents:
5dfeb4c
Message:

Remove group passwords and introduce new tokenizer

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    r5dfeb4c r677a45b  
    177177                        return;
    178178                } else {
    179                         if ((ig = icb_addgroup(is, group, NULL)) == NULL) {
     179                        if ((ig = icb_addgroup(is, group)) == NULL) {
    180180                                icb_error(is, "Can't create group");
    181181                                return;
  • icb.c

    r5dfeb4c r677a45b  
    168168                        return (1);
    169169                } else {
    170                         if ((ig = icb_addgroup(is, group, NULL)) == NULL) {
     170                        if ((ig = icb_addgroup(is, group)) == NULL) {
    171171                                icb_error(is, "Can't create group %s", group);
    172172                                return (0);
     
    441441 */
    442442struct icb_group *
    443 icb_addgroup(struct icb_session *is, char *name, char *mpass)
     443icb_addgroup(struct icb_session *is, char *name)
    444444{
    445445        struct icb_group *ig;
     
    448448                return (NULL);
    449449        strlcpy(ig->name, name, sizeof ig->name);
    450         if (mpass)
    451                 strlcpy(ig->mpass, mpass, sizeof ig->mpass);
    452450        if (is)
    453451                ig->mod = is;
     
    628626
    629627/*
     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 */
     633int
     634icb_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/*
    630667 *  icb_vis: strnvis-like function that escapes percentages as well
    631668 */
  • icb.h

    r5dfeb4c r677a45b  
    2828#define ICB_MAXGRPLEN            32
    2929#define ICB_MAXNICKLEN           32
    30 #define ICB_MAXPASSLEN           32
    3130#define ICB_MAXTOPICLEN          160
    3231#define ICB_MAXHOSTLEN           40
     
    107106struct icb_group {
    108107        char                     name[ICB_MAXGRPLEN];
    109         char                     mpass[ICB_MAXPASSLEN];
    110108        char                     topic[ICB_MAXTOPICLEN];
    111109        LIST_ENTRY(icb_group)    entry;
     
    125123/* icb.c */
    126124struct icb_group *
    127                 icb_addgroup(struct icb_session *, char *, char *);
     125                icb_addgroup(struct icb_session *, char *);
    128126void            icb_cmdout(struct icb_session *, int, char *);
    129127void            icb_delgroup(struct icb_group *);
     
    143141                    int, const char *, ...);
    144142void            icb_who(struct icb_session *, struct icb_group *);
     143int             icb_token(char *, int, char **, char *, int, int);
    145144int             icb_vis(char *, const char *, size_t, int);
  • icbd.c

    r5dfeb4c r677a45b  
    6565void icbd_dispatch(struct bufferevent *, void *);
    6666void icbd_log(struct icb_session *, int, const char *, ...);
    67 void icbd_grplist(char *);
    6867void icbd_restrict(void);
    6968void icbd_send(struct icb_session *, char *, ssize_t);
     
    7978        int ch, nsocks = 0, save_errno = 0;
    8079        int inet4 = 0, inet6 = 0;
     80        char group[ICB_MAXGRPLEN], *grplist = NULL;
     81        char *ptr = NULL;
    8182
    8283        /* init group lists before calling icb_addgroup */
     
    9899                        break;
    99100                case 'G':
    100                         icbd_grplist(optarg);
     101                        grplist = optarg;
    101102                        break;
    102103                case 'L':
     
    124125
    125126        /* 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)
    127128                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        }
    128136
    129137        if (argc == 0)
     
    492500
    493501void
    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 void
    522502icbd_modupdate(void)
    523503{
Note: See TracChangeset for help on using the changeset viewer.