⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log_pgsql.c

📁 功能强大的ftp服务器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    const char *bandwidth_dl = NULL;   /* stored bandwidth DL */#endif    char *escaped_account = NULL;    char *escaped_ip = NULL;    char *escaped_port = NULL;    char *escaped_peer_ip = NULL;    char *escaped_decimal_ip = NULL;        char *scrambled_password = NULL;    int committed = 1;    int crypto_crypt = 0, crypto_plain = 0, crypto_md5 = 0;    unsigned long decimal_ip_num = 0UL;    char decimal_ip[42];    char hbuf[NI_MAXHOST];    char pbuf[NI_MAXSERV];    char phbuf[NI_MAXHOST];        result->auth_ok = 0;    if (pw_pgsql_validate_name(account) != 0) {        goto bye;    }    if (getnameinfo((const struct sockaddr *) sa, STORAGE_LEN(*sa),                    hbuf, sizeof hbuf, pbuf, sizeof pbuf,                    NI_NUMERICHOST | NI_NUMERICSERV) != 0 ||        getnameinfo((const struct sockaddr *) peer, STORAGE_LEN(*peer),                    phbuf, sizeof phbuf, NULL, (size_t) 0U,                    NI_NUMERICHOST) != 0) {        goto bye;    }    *decimal_ip = 0;    if (STORAGE_FAMILY(*peer) == AF_INET) {        const unsigned char *decimal_ip_raw =            (const unsigned char *) &(STORAGE_SIN_ADDR(*peer));        decimal_ip_num = (decimal_ip_raw[0] << 24) |             (decimal_ip_raw[1] << 16) | (decimal_ip_raw[2] << 8) |            decimal_ip_raw[3];        if (SNCHECK(snprintf(decimal_ip, sizeof decimal_ip,                             "%lu", decimal_ip_num), sizeof decimal_ip)) {            goto bye;        }    }    if (pw_pgsql_connect(&id_sql_server) != 0) {        goto bye;    }    if ((escaped_account =          pw_pgsql_escape_string(account)) == NULL) {        goto bye;    }    if ((escaped_ip =          pw_pgsql_escape_string(hbuf)) == NULL) {        goto bye;    }    if ((escaped_port =          pw_pgsql_escape_string(pbuf)) == NULL) {        goto bye;    }    if ((escaped_peer_ip =          pw_pgsql_escape_string(phbuf)) == NULL) {        goto bye;    }    if ((escaped_decimal_ip =          pw_pgsql_escape_string(decimal_ip)) == NULL) {        goto bye;    }    if (pw_pgsql_simplequery(id_sql_server, PGSQL_TRANSACTION_START) == 0) {        committed = 0;    }    if ((spwd = pw_pgsql_getquery(id_sql_server, sqlreq_getpw,                                  escaped_account, escaped_ip,                                  escaped_port, escaped_peer_ip,                                  escaped_decimal_ip)) == NULL) {        goto bye;    }    if (uid == NULL) {        uid = pw_pgsql_getquery(id_sql_server, sqlreq_getuid,                                escaped_account, escaped_ip,                                 escaped_port, escaped_peer_ip,                                escaped_decimal_ip);    }    if (uid == NULL) {        goto bye;    }    if (gid == NULL) {        gid = pw_pgsql_getquery(id_sql_server, sqlreq_getgid,                                escaped_account, escaped_ip,                                escaped_port, escaped_peer_ip,                                escaped_decimal_ip);    }    if (gid == NULL) {        goto bye;    }    if ((dir = pw_pgsql_getquery(id_sql_server, sqlreq_getdir,                                 escaped_account, escaped_ip,                                 escaped_port, escaped_peer_ip,                                 escaped_decimal_ip)) == NULL) {        goto bye;    }    result->auth_ok--;                  /* -1 */    if (strcasecmp(crypto, PASSWD_SQL_ANY) == 0) {        crypto_crypt++;        crypto_md5++;    } else if (strcasecmp(crypto, PASSWD_SQL_CRYPT) == 0) {        crypto_crypt++;    } else if (strcasecmp(crypto, PASSWD_SQL_MD5) == 0) {        crypto_md5++;    } else {                           /* default to plaintext */        crypto_plain++;    }    if (crypto_crypt != 0) {        register const char *crypted;                if ((crypted = (const char *) crypt(password, spwd)) != NULL &&            strcmp(crypted, spwd) == 0) {            goto auth_ok;        }    }    if (crypto_md5 != 0) {        register const char *crypted;                if ((crypted = (const char *) crypto_hash_md5(password, 1)) != NULL &&            strcmp(crypted, spwd) == 0) {            goto auth_ok;        }    }    if (crypto_plain != 0) {        if (*password != 0 &&    /* refuse null cleartext passwords */            strcmp(password, spwd) == 0) {            goto auth_ok;        }    }    goto bye;        auth_ok:    /*     * do *NOT* accept root uid/gid - if the database is compromized, the FTP     * server could also be rooted.     */    result->uid = (uid_t) strtoul(uid, NULL, 10);    if (result->uid <= (uid_t) 0) {        struct passwd *pw;                if ((pw = getpwnam(uid)) == NULL || pw->pw_uid <= (uid_t) 0) {            goto bye;        }        result->uid = pw->pw_uid;    }    result->gid = (gid_t) strtoul(gid, NULL, 10);    if (result->gid <= (gid_t) 0) {        struct group *gr;                if ((gr = getgrnam(gid)) == NULL || gr->gr_gid <= (gid_t) 0) {            goto bye;        }        result->gid = gr->gr_gid;    }        result->dir = dir;    dir = NULL;    #ifdef QUOTAS    if ((sqta_fs = pw_pgsql_getquery(id_sql_server, sqlreq_getqta_fs,                                     escaped_account, escaped_ip,                                     escaped_port, escaped_peer_ip,                                     escaped_decimal_ip)) != NULL) {        const unsigned long long q = strtoull(sqta_fs, NULL, 10);                if (q > 0ULL) {            result->user_quota_files = q;            result->quota_files_changed = 1;        }    }    if ((sqta_sz = pw_pgsql_getquery(id_sql_server, sqlreq_getqta_sz,                                     escaped_account, escaped_ip,                                     escaped_port, escaped_peer_ip,                                     escaped_decimal_ip)) != NULL) {        const unsigned long long q = strtoull(sqta_sz, NULL, 10);                if (q > 0ULL) {            result->user_quota_size = q * (1024UL * 1024UL);            result->quota_size_changed = 1;        }    }#endif           #ifdef RATIOS    if ((ratio_ul = pw_pgsql_getquery(id_sql_server, sqlreq_getratio_ul,                                      escaped_account, escaped_ip,                                      escaped_port, escaped_peer_ip,                                      escaped_decimal_ip)) != NULL) {        const unsigned int q = (unsigned int) strtoul(ratio_ul, NULL, 10);                if (q > 0U) {            result->ratio_upload = q;            result->ratio_ul_changed = 1;        }    }    if ((ratio_dl = pw_pgsql_getquery(id_sql_server, sqlreq_getratio_dl,                                      escaped_account, escaped_ip,                                      escaped_port, escaped_peer_ip,                                      escaped_decimal_ip)) != NULL) {        const unsigned int q = (unsigned int) strtoul(ratio_dl, NULL, 10);                if (q > 0U) {            result->ratio_download = q;            result->ratio_dl_changed = 1;        }    }#endif#ifdef THROTTLING    if ((bandwidth_ul = pw_pgsql_getquery(id_sql_server, sqlreq_getbandwidth_ul,                                          escaped_account, escaped_ip,                                          escaped_port, escaped_peer_ip,                                          escaped_decimal_ip)) != NULL) {        const unsigned long q = (unsigned long) strtoul(bandwidth_ul, NULL, 10);                if (q > 0UL) {            result->throttling_bandwidth_ul = q * 1024UL;            result->throttling_ul_changed = 1;        }    }    if ((bandwidth_dl = pw_pgsql_getquery(id_sql_server, sqlreq_getbandwidth_dl,                                          escaped_account, escaped_ip,                                          escaped_port, escaped_peer_ip,                                          escaped_decimal_ip)) != NULL) {        const unsigned long q = (unsigned long) strtoul(bandwidth_dl, NULL, 10);                if (q > 0UL) {            result->throttling_bandwidth_dl = q * 1024UL;            result->throttling_dl_changed = 1;        }    }#endif        result->slow_tilde_expansion = 1;    result->auth_ok =- result->auth_ok;    bye:    if (committed == 0) {        (void) pw_pgsql_simplequery(id_sql_server, PGSQL_TRANSACTION_END);    }    if (id_sql_server != NULL) {        PQfinish(id_sql_server);    }    if (spwd != NULL) {        free((void *) spwd);    }    if (uid != NULL) {        free((void *) uid);    }    if (gid != NULL) {        free((void *) gid);    }    if (dir != NULL) {        free((void *) dir);    }    if (scrambled_password != NULL) {        free(scrambled_password);    }#ifdef QUOTAS    if (sqta_fs != NULL) {        free((void *) sqta_fs);    }    if (sqta_sz != NULL) {        free((void *) sqta_sz);    }#endif    #ifdef RATIOS    if (ratio_ul != NULL) {        free((void *) ratio_ul);    }    if (ratio_dl != NULL) {        free((void *) ratio_dl);    }#endif    #ifdef THROTTLING    if (bandwidth_ul != NULL) {        free((void *) bandwidth_ul);    }    if (bandwidth_dl != NULL) {        free((void *) bandwidth_dl);    }#endif        if (escaped_account != NULL) {        free((void *) escaped_account);    }    if (escaped_ip != NULL) {        free((void *) escaped_ip);    }    if (escaped_port != NULL) {        free((void *) escaped_port);    }    if (escaped_peer_ip != NULL) {        free((void *) escaped_peer_ip);    }    if (escaped_decimal_ip != NULL) {        free((void *) escaped_decimal_ip);    }    }void pw_pgsql_parse(const char * const file){    if (generic_parser(file, pgsql_config_keywords) != 0) {        die(421, LOG_ERR, MSG_CONF_ERR ": " MSG_ILLEGAL_CONFIG_FILE_SQL ": %s" , file);    }        if (server == NULL ) {        die(421, LOG_ERR, MSG_SQL_MISSING_SERVER);            }    if (port_s != NULL) {        port = atoi(port_s);        if (port <= 0 || port > 65535) {            port = PGSQL_DEFAULT_PORT;        }        free(port_s);        port_s = NULL;    }}#define ZFREE(X) if ((X) != NULL) { free(X); (X) = NULL; }void pw_pgsql_exit(void){    ZFREE(server);    ZFREE(port_s);    port = -1;        ZFREE(user);    ZFREE(pw);    ZFREE(db);    ZFREE(crypto);    ZFREE(sqlreq_getpw);    ZFREE(sqlreq_getuid);    ZFREE(sql_default_uid);    ZFREE(sqlreq_getgid);    ZFREE(sql_default_gid);    ZFREE(sqlreq_getdir);#ifdef QUOTAS    ZFREE(sqlreq_getqta_fs);    ZFREE(sqlreq_getqta_sz);#endif#ifdef RATIOS    ZFREE(sqlreq_getratio_ul);    ZFREE(sqlreq_getratio_dl);    #endif#ifdef THROTTLING    ZFREE(sqlreq_getbandwidth_ul);    ZFREE(sqlreq_getbandwidth_dl);    #endif}#elseextern signed char v6ready;#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -