Changeset 1d2125a in code


Ignore:
Timestamp:
Mar 2, 2014, 1:50:57 AM (11 years ago)
Author:
Mike Belopuhov <mike@…>
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)
Message:

Add support for the moderator table that specifies (currently up
to 50) users that are allowed to become moderators.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icb.c

    rd554223 r1d2125a  
    3535void   icb_login(struct icb_session *, char *, char *, char *);
    3636int    icb_dowho(struct icb_session *, struct icb_group *);
     37int    icb_modpermit(struct icb_session *);
    3738char  *icb_nextfield(char **);
    3839
     
    518519
    519520/*
     521 *  icb_modpermit: checks user against the moderators table if it has
     522 *                 been populated
     523 */
     524int
     525icb_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/*
    520538 *  icb_pass: passes moderation of group "ig" from "from" to "to",
    521539 *            returns -1 if "from" is not a moderator, 1 if passed
     
    530548                return (-1);
    531549        if (!from && !to)
     550                return (-1);
     551        if (to && !icb_modpermit(to))
    532552                return (-1);
    533553        ig->mod = to;
  • icb.h

    rd554223 r1d2125a  
    2323#define ICB_MAXPASSLEN           32
    2424#define ICB_MAXTOPICLEN          160
     25#define ICB_MTABLEN              50 /* XXX */
    2526
    2627#define ICB_M_LOGIN              'a'
     
    120121void icb_input(struct icb_session *);
    121122int  icb_ismod(struct icb_group *, struct icb_session *);
     123int  icb_modpermit(struct icb_session *);
    122124int  icb_pass(struct icb_group *, struct icb_session *, struct icb_session *);
    123125void icb_privmsg(struct icb_session *, char *, char *);
  • icbd.c

    rd554223 r1d2125a  
    4444extern char *__progname;
    4545
     46char modtab[ICB_MTABLEN][ICB_MAXNICKLEN];
     47int  modtabcnt;
    4648char srvname[MAXHOSTNAMELEN];
    4749int  creategroups;
     
    5759void icbd_log(struct icb_session *, int, const char *, ...);
    5860void icbd_grplist(char *);
     61void icbd_modtab(char *);
    5962void icbd_restrict(void);
    6063void icbd_write(struct icb_session *, char *, ssize_t);
     
    7174        icb_init(&ic);
    7275
    73         while ((ch = getopt(argc, argv, "46CdG:S:v")) != -1)
     76        while ((ch = getopt(argc, argv, "46CdG:M:S:v")) != -1)
    7477                switch (ch) {
    7578                case '4':
     
    8790                case 'G':
    8891                        icbd_grplist(optarg);
     92                        break;
     93                case 'M':
     94                        icbd_modtab(optarg);
    8995                        break;
    9096                case 'S':
     
    276282{
    277283        (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);
    279285        exit(EX_USAGE);
    280286}
     
    455461}
    456462
     463void
     464icbd_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
    457500time_t
    458501getmonotime(void)
Note: See TracChangeset for help on using the changeset viewer.