Changeset 751 for branches/ithildin-1.1


Ignore:
Timestamp:
06/23/06 01:43:45 (6 years ago)
Author:
wd
Message:

Add XINFO priv creation for all XINFOs.

Location:
branches/ithildin-1.1/modules/ircd
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ithildin-1.1/modules/ircd/addons/acl.c

    r732 r751  
    748748    LIST_ALLOC(acl.stage3_list); 
    749749 
    750     add_xinfo_handler(xinfo_acl_handler, "ACL", XINFO_HANDLER_OPER, NULL, 
     750    add_xinfo_handler(xinfo_acl_handler, "ACL", XINFO_HANDLER_OPER,  
    751751            "Provides information about the server Access Control List"); 
    752752 
  • branches/ithildin-1.1/modules/ircd/addons/hostcrypt.c

    r579 r751  
    372372    char addr[IPADDR_SIZE]; 
    373373    size_t alen; 
    374  
    375 #ifdef INET6 
    376     if (inet_pton(PF_INET6, cli->ip, addr) == 1) 
    377         alen = IPADDR_SIZE; 
    378     else 
    379 #endif 
    380         if (inet_pton(PF_INET, cli->ip, addr) == 1) 
     374    char *s; 
     375    bool ip = false; 
     376    int family = PF_INET;  
     377#ifdef INET6 
     378    struct in6_addr i6a; 
     379#endif 
     380    struct in_addr ia; 
     381 
     382    /* See if it is an IP address.. */ 
     383#ifdef INET6 
     384    if ((s = strchr(cli->orighost, ':')) != NULL && 
     385            inet_pton(PF_INET6, cli->orighost, &i6a) == 1) { 
     386        ip = true; 
     387        family = PF_INET6; 
     388    } else 
     389#endif 
     390    if ((s = strrchr(cli->orighost, '.')) != NULL && 
     391            inet_pton(PF_INET, cli->orighost, &ia) == 1) 
     392    ip = true; 
     393 
     394    if (ip) { 
     395        inet_pton(family, cli->orighost, addr); 
     396#ifdef INET6 
     397        if (family == PF_INET6) 
     398            alen = IPADDR_SIZE; 
     399        else 
     400#endif 
    381401            alen = 4; 
     402 
     403        md5_data(addr, alen, md5buf); 
     404        memset(addr + (alen / 2), 0, alen / 2); 
     405        md5_data(addr, alen, md5buf + 32); 
     406    } else { 
     407        alen = strlen(cli->orighost); 
     408        md5_data(cli->orighost, alen, md5buf); 
     409         
     410        /* extract only the interesting part of the hostname (domain.tld). 
     411         * For hostnames which are merely domain.tld to begin with, we 
     412         * provide the first set of md5 data as additional "seed" for them. */ 
     413        s = strrchr(cli->orighost, '.'); 
     414        if (s == NULL) 
     415            /* singleton string like 'localhost' */ 
     416            sprintf(buf, "%32s.%s", md5buf, cli->orighost); 
    382417        else { 
    383             inet_pton(PF_INET, "0.0.0.0", addr); 
    384             alen = 4; 
     418            while (*s != '.' && s > cli->orighost) 
     419                s--; /* walk backwards to find the . or beginning of string */ 
     420            if (s == cli->orighost) 
     421                /* host is in pure domain.tld form */ 
     422                sprintf(buf, "%32s.%s", md5buf, cli->orighost); 
     423            else 
     424                /* s is the second to last . in the string now */ 
     425                sprintf(buf, "%s", s + 1); 
    385426        } 
    386  
    387     md5_data(addr, alen, md5buf); 
    388     memset(addr + (alen / 2), 0, alen / 2); 
    389     md5_data(addr, alen, md5buf + 32); 
     427        /* buf now contains the host we wish to md5 on */ 
     428        alen = strlen(buf); 
     429        md5_data(buf, alen, md5buf + 32); 
     430    } 
    390431     
    391432    /* okay, md5buf is now a 64 byte long base16 encoded string.  decode it 
  • branches/ithildin-1.1/modules/ircd/addons/quarantine.c

    r579 r751  
    237237    } 
    238238 
    239     add_xinfo_handler(xinfo_quarantine_handler, "QUARANTINE", 0, NULL, 
     239    add_xinfo_handler(xinfo_quarantine_handler, "QUARANTINE", 0,  
    240240            "Provides a list of nickname and channel quarantines"); 
    241241 
  • branches/ithildin-1.1/modules/ircd/command.c

    r717 r751  
    401401            } 
    402402        } 
    403         /* check operator and command use privileges */ 
     403        /* check operator and command use privileges.  Why do this only for 
     404         * local clients?  Because we need to assume that even if we are not 
     405         * configured to accept commands from a client, every other server 
     406         * is.  Without a distributed privilege understanding we have to 
     407         * assume positive intent. */ 
    404408        if ((cmd->client.flags & COMMAND_FL_OPERATOR && !OPER(cli)) || 
    405409                !BPRIV(cli, cmd->priv)) { 
  • branches/ithildin-1.1/modules/ircd/commands/oper.c

    r579 r751  
    2323MODULE_LOADER(oper) { 
    2424 
    25     add_xinfo_handler(xinfo_oper_func, "OPERATORS", 0, NULL, 
     25    add_xinfo_handler(xinfo_oper_func, "OPERATORS", 0, 
    2626            "Provides information about server operators"); 
    2727 
  • branches/ithildin-1.1/modules/ircd/commands/xinfo.c

    r579 r751  
    3030MODULE_LOADER(xinfo) { 
    3131 
    32     add_xinfo_handler(xinfo_class_handler, "CLASS", 0, NULL, 
     32    add_xinfo_handler(xinfo_class_handler, "CLASS", 0, 
    3333            "Provides information about server connection classes"); 
    34     add_xinfo_handler(xinfo_client_handler, "CLIENT", XINFO_HANDLER_OPER, NULL, 
     34    add_xinfo_handler(xinfo_client_handler, "CLIENT", XINFO_HANDLER_OPER, 
    3535            "Provices information about clients on this server"); 
    3636    add_xinfo_handler(xinfo_connects_handler, "CONNECTS", XINFO_HANDLER_OPER, 
    37             NULL, "Shows information about server uplinks"); 
    38     add_xinfo_handler(xinfo_hash_handler, "HASH", XINFO_HANDLER_OPER, NULL, 
     37            "Shows information about server uplinks"); 
     38    add_xinfo_handler(xinfo_hash_handler, "HASH", XINFO_HANDLER_OPER, 
    3939            "Shows hash table statistics."); 
    40     add_xinfo_handler(xinfo_me_handler, "ME", XINFO_HANDLER_LOCAL, NULL, 
     40    add_xinfo_handler(xinfo_me_handler, "ME", XINFO_HANDLER_LOCAL, 
    4141            "Provides information about your connection statistics"); 
    4242    add_xinfo_handler(xinfo_privilege_handler, "PRIVILEGE", 
    43             XINFO_HANDLER_LOCAL | XINFO_HANDLER_OPER, NULL, 
     43            XINFO_HANDLER_LOCAL | XINFO_HANDLER_OPER, 
    4444            "Provides information about available privileges"); 
    45     add_xinfo_handler(xinfo_server_handler, "SERVER", 0, NULL, 
     45    add_xinfo_handler(xinfo_server_handler, "SERVER", 0, 
    4646            "Provides information about this (or other) servers"); 
    47     add_xinfo_handler(xinfo_xinfo_handler, "XINFO", 0, NULL, 
     47    add_xinfo_handler(xinfo_xinfo_handler, "XINFO", 0, 
    4848            "Provides a list of available XINFO query-handlers"); 
    4949 
     
    136136        return COMMAND_WEIGHT_LOW; /* silently ignore these */ 
    137137    if ((xhp->flags & XINFO_HANDLER_OPER && !OPER(cli)) || 
    138             (xhp->flags & XINFO_HANDLER_PRIV && !BPRIV(cli, xhp->priv))) { 
     138            !BPRIV(cli, xhp->priv)) { 
    139139        sendto_one(cli, RPL_FMT(cli, ERR_NOPRIVILEGES)); 
    140140        return COMMAND_WEIGHT_LOW; 
     
    425425            continue; /* non-local */ 
    426426        if ((xhp->flags & XINFO_HANDLER_OPER && !OPER(cli)) || 
    427                 (xhp->flags & XINFO_HANDLER_PRIV && !BPRIV(cli, xhp->priv))) 
     427                !BPRIV(cli, xhp->priv)) 
    428428            continue; /* not privileged */ 
    429429 
  • branches/ithildin-1.1/modules/ircd/support.c

    r579 r751  
    3535    ip = malloc(sizeof(struct isupport)); 
    3636    memset(ip, 0, sizeof(struct isupport)); 
    37     ip->name = strdup(name); 
     37    strlcpy(ip->name, name, ISUPPORTNAME_MAXLEN + 1); 
    3838    /* now insert into a list.  we alphabetically sort our list, just 
    3939     * because I like to. :) */ 
     
    8484    if (ip != NULL) { 
    8585        LIST_REMOVE(ip, lp); 
    86         free(ip->name); 
    8786        if (!(ip->flags & ISUPPORT_FL_PRIV) && ip->value.str != NULL) 
    8887            free(ip->value.str); 
     
    144143 * fifth is a description of the handler (usually short).  The function returns 
    145144 * non-zero upon successful installation. */ 
    146 int add_xinfo_handler(xinfo_func func, char *name, int flags, 
    147         void *udata, char *desc) { 
     145int add_xinfo_handler(xinfo_func func, char *name, int flags, char *desc) { 
    148146    struct xinfo_handler *xhp = find_xinfo_handler(name); 
     147    uint64_t i64 = 1; 
     148    char privname[XINFONAME_MAXLEN + 1 + 6]; /* add 6 for "xinfo-" tag */ 
    149149 
    150150    if (xhp != NULL) 
     
    153153    xhp = malloc(sizeof(struct xinfo_handler)); 
    154154    xhp->func = func; 
    155     xhp->name = strdup(name); 
     155    strlcpy(xhp->name, name, XINFONAME_MAXLEN + 1); 
    156156    xhp->flags = flags; 
    157     if (xhp->flags & XINFO_HANDLER_PRIV) 
    158         xhp->priv = *(int *)udata; 
    159     else 
    160         xhp->priv = -1; 
     157 
     158    /* Create a privilege for them.  Always bool, this is simply a "yes/no" 
     159     * flag to whether or not this information is available.  Always default 
     160     * to 1 */ 
     161    sprintf(privname, "xinfo-%s", xhp->name); 
     162    xhp->priv = create_privilege(privname, PRIVILEGE_FL_BOOL, &i64, NULL); 
     163 
    161164    xhp->desc = strdup((desc != NULL ? desc : "no description")); 
    162165 
  • branches/ithildin-1.1/modules/ircd/support.h

    r593 r751  
    1111#define IRCD_SUPPORT_H 
    1212 
     13#define ISUPPORTNAME_MAXLEN 31 /* XXX: what does the spec say, if anything, 
     14                                  about this...? */ 
     15 
    1316/* a feature may have a straightforward string value, or it may have a value 
    1417 * which is connect-time dependent.  features which are connect-time dependent 
    1518 * are assumed to be privileges, but see below. */ 
    1619struct isupport { 
    17     char    *name;        /* name of the feature supported. */ 
     20    char name[ISUPPORTNAME_MAXLEN + 1]; 
    1821    union { 
    1922        char *str;        /* string value */ 
     
    4750        char **argv __UNUSED) 
    4851 
     52#define XINFONAME_MAXLEN ISUPPORTNAME_MAXLEN 
     53 
    4954/* The xinfo_handler structure contains a each xinfo handler's necessary 
    5055 * details. */ 
    5156struct xinfo_handler { 
    52     char *name; 
     57    char name[XINFONAME_MAXLEN + 1]; 
    5358    char *desc; 
    5459#define XINFO_HANDLER_LOCAL 0x1 
    5560#define XINFO_HANDLER_OPER  0x2 
    56 #define XINFO_HANDLER_PRIV  0x4 
    5761    int flags; 
    58     int priv; /* privilege, if any */ 
     62    int priv; /* privilege */ 
    5963    xinfo_func func; 
    6064 
     
    6468#define XINFO_LEN 512 
    6569 
    66 int add_xinfo_handler(xinfo_func, char *, int, void *, char *); 
     70int add_xinfo_handler(xinfo_func, char *, int, char *); 
    6771struct xinfo_handler *find_xinfo_handler(char *); 
    6872void remove_xinfo_handler(xinfo_func); 
Note: See TracChangeset for help on using the changeset viewer.