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

📄 log_mysql.c

📁 功能强大的ftp服务器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                    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_mysql_connect(&id_sql_server) != 0) {        goto bye;    }    if ((escaped_account =          pw_mysql_escape_string(id_sql_server, account)) == NULL) {        goto bye;    }    if ((escaped_ip =          pw_mysql_escape_string(id_sql_server, hbuf)) == NULL) {        goto bye;    }    if ((escaped_port =          pw_mysql_escape_string(id_sql_server, pbuf)) == NULL) {        goto bye;    }    if ((escaped_peer_ip =          pw_mysql_escape_string(id_sql_server, phbuf)) == NULL) {        goto bye;    }    if ((escaped_decimal_ip =          pw_mysql_escape_string(id_sql_server, decimal_ip)) == NULL) {        goto bye;    }    if (transactions != NULL && strcasecmp(transactions, "on") == 0) {        if (pw_mysql_simplequery(id_sql_server, MYSQL_TRANSACTION_START) == 0) {            committed = 0;        }    }    if ((spwd = pw_mysql_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_mysql_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_mysql_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_mysql_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_mysql++;        crypto_md5++;    } else if (strcasecmp(crypto, PASSWD_SQL_CRYPT) == 0) {        crypto_crypt++;    } else if (strcasecmp(crypto, PASSWD_SQL_MYSQL) == 0) {        crypto_mysql++;    } 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_mysql != 0) {        unsigned long hash_res[2];        char scrambled_password[MYSQL_CRYPT_LEN];                hash_password(hash_res, password);        snprintf(scrambled_password, sizeof scrambled_password, "%08lx%08lx",                  hash_res[0], hash_res[1]);        if (strcmp(scrambled_password, 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 || (gid_t) gr->gr_gid <= (gid_t) 0) {            goto bye;        }        result->gid = gr->gr_gid;    }        result->dir = dir;    dir = NULL;    #ifdef QUOTAS    if ((sqta_fs = pw_mysql_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_mysql_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_mysql_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_mysql_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_mysql_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_mysql_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 = !tildexp;    result->auth_ok =- result->auth_ok;    bye:    if (committed == 0) {        (void) pw_mysql_simplequery(id_sql_server, MYSQL_TRANSACTION_END);    }    if (id_sql_server != NULL) {        mysql_close(id_sql_server);    }    free((void *) spwd);    free((void *) uid);    free((void *) gid);     free((void *) dir);#ifdef QUOTAS    free((void *) sqta_fs);    free((void *) sqta_sz);#endif    #ifdef RATIOS    free((void *) ratio_ul);    free((void *) ratio_dl);#endif    #ifdef THROTTLING    free((void *) bandwidth_ul);    free((void *) bandwidth_dl);#endif        free((void *) escaped_account);    free((void *) escaped_ip);    free((void *) escaped_port);    free((void *) escaped_peer_ip);    free((void *) escaped_decimal_ip);}void pw_mysql_parse(const char * const file){    if (generic_parser(file, mysql_config_keywords) != 0) {        die(421, LOG_ERR, MSG_CONF_ERR ": " MSG_ILLEGAL_CONFIG_FILE_SQL ": %s",	    file);    }        if (server == NULL && socket_path == NULL) {        die(421, LOG_ERR, MSG_SQL_MISSING_SERVER);            }    if (server != NULL && socket_path != NULL) {        free(socket_path);        socket_path = NULL;    }    if (tildexp_s != NULL) {	if ((tildexp = atoi(tildexp_s)) < 0) {	    tildexp = 0;	}	free(tildexp_s);	tildexp_s = NULL;	    }            if (port_s != NULL) {        port = atoi(port_s);        if (port <= 0 || port > 65535) {            port = MYSQL_DEFAULT_PORT;        }        free(port_s);        port_s = NULL;    }        }#define ZFREE(X) do { free(X); (X) = NULL; } while (0)void pw_mysql_exit(void){    ZFREE(server);    ZFREE(port_s);    port = -1;        ZFREE(socket_path);    ZFREE(user);    ZFREE(pw);    ZFREE(db);    ZFREE(crypto);    ZFREE(transactions);    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 + -