/* This is just to check if a Boolean value is set in the environment. */
static int is_env_set(const char *name)
{
    char        regbuf[10]; /* true/false, 1/0, on/off, yes/no */
    const char* reg;

    reg = CORE_REG_GET("", name, regbuf, sizeof(regbuf)-1, "");
    return (reg  &&  *reg) ? 1 : 0;
}
Exemple #2
0
static char* s_ServiceName(const char* service,
                           int/*bool*/ ismask, size_t depth)
{
    char   buf[128];
    char   srv[128];
    size_t len;
    char*  s;

    if (depth > 7) {
        assert(service  &&  *service);
        CORE_LOGF_X(7, eLOG_Error,
                    ("[%s]  Maximal service name recursion depth reached: %lu",
                     service, (unsigned long) depth));
        return 0/*failure*/;
    }
    len = 0;
    assert(sizeof(buf) > sizeof(CONN_SERVICE_NAME));
    if (!service  ||  (!ismask  &&  (!*service  ||  strpbrk(service, "?*")))
        ||  (len = strlen(service)) >= sizeof(buf)-sizeof(CONN_SERVICE_NAME)) {
        CORE_LOGF_X(8, eLOG_Error,
                    ("%s%s%s%s service name",
                     !service  ||  !*service ? "" : "[",
                     !service ? "" : service,
                     !service  ||  !*service ? "" : "]  ",
                     !service ? "NULL" : !*service ? "Empty" :
                     len < sizeof(buf)-sizeof(CONN_SERVICE_NAME) ? "Invalid" :
                     "Too long"));
        return 0/*failure*/;
    }
    if (!s_Fast  &&  !ismask) {
        s = (char*) memcpy(buf, service, len) + len;
        *s++ = '_';
        memcpy(s, CONN_SERVICE_NAME, sizeof(CONN_SERVICE_NAME));
        /* Looking for "service_CONN_SERVICE_NAME" in the environment */
        if (!(s = getenv(strupr(buf)))  ||  !*s) {
            /* Looking for "CONN_SERVICE_NAME" in registry section [service] */
            buf[len++] = '\0';
            CORE_REG_GET(buf, buf + len, srv, sizeof(srv), 0);
            s = srv;
        }
        if (*s  &&  strcasecmp(s, service) != 0)
            return s_ServiceName(s, ismask, ++depth);
    }
    return strdup(service);
}
Exemple #3
0
static int/*bool*/ s_LoadSingleService(const char* name, SERV_ITER iter)
{
    struct SLOCAL_Data* data = (struct SLOCAL_Data*) iter->data;
    const TSERV_Type type = iter->type & ~fSERV_Firewall;
    int/*bool*/ ok = 0/*failed*/;
    SSERV_Info* info;
    char* buf;
    int n;

    if (!(buf =
          (char*) malloc(strlen(name) + sizeof(REG_CONN_LOCAL_SERVER) + 80))) {
        return 0/*failed*/;
    }

    info = 0;
    for (n = 0;  n <= 100;  n++) {
        char service[1024];
        const char* c;

        if (info) {
            free((void*) info);
            info = 0;
        }
        sprintf(buf, "%s_" REG_CONN_LOCAL_SERVER "_%d", name, n);
        if (!(c = getenv(buf))  &&  !(c = getenv(strupr(buf)))) {
            char*  b = buf + strlen(name);
            size_t len;
            *b++ = '\0';
            CORE_REG_GET(buf, b, service, sizeof(service) - 1, 0);
            len = strlen(service);
            if (len > 1  &&  (service[0] == '"'  ||  service[0] == '\'')
                &&  service[len - 1] == service[0]  &&  (len -= 2) > 0) {
                memmove(service, service + 1, len);
                service[len] = '\0';
            }
            if (!len)
                continue;
            c = service;
        }
        if (!(info = SERV_ReadInfoEx
              (c, iter->ismask  ||  iter->reverse_dns ? name : ""))) {
            continue;
        }
        if (iter->external  &&  info->locl)
            continue;  /* external mapping for local server not allowed */
        if (!info->host  ||  (info->locl & 0xF0)) {
            unsigned int localhost = SOCK_GetLocalHostAddress(eDefault);
            if (!info->host)
                info->host = localhost;
            if ((info->locl & 0xF0)  &&  info->host != localhost)
                continue;  /* private server */
        }
        if (!iter->reverse_dns  &&  info->type != fSERV_Dns) {
            if (type != fSERV_Any  &&  !(type & info->type))
                continue;  /* type doesn't match */
            if (type == fSERV_Any  &&  info->type == fSERV_Dns)
                continue;  /* DNS entries have to be req'd explicitly */
            if (iter->stateless && info->sful && !(info->type & fSERV_Http))
                continue;  /* skip stateful only servers */
        }
        if (!info->rate)
            info->rate = LBSM_DEFAULT_RATE;
        if (!info->time)
            info->time = LBSM_DEFAULT_TIME;

        if (!s_AddService(info, data))
            break;

        info = 0;
        ok = 1/*succeeded*/;
    }
    if (info)
        free((void*) info);

    free(buf);
    return ok/*whatever*/;
}