네 가능합니다. qmail-queue를 KeyDB로 연동했던 것과 동일한 원리로, vpopmail의 MySQL 인증 모듈( vmysql.c )을 KeyDB(hiredis) 통신 코드로 완전히 대체하여 모든 계정 정보 조회 및 인증 I/O를 메모리 DB로 넘길 수 있습니다. vpopmail 소스의 vmysql.c 를 덮어쓰는 방식으로 적용하여, 기존 빌드 시스템(Makefile)을 건드리지 않고 자연스럽게 KeyDB 백엔드로 컴파일되도록 하는 전체 소스 코드를 제공합니다. 1. vpopmail 소스 수정 ( vmysql.c 덮어쓰기) vpopmail 소스 디렉토리로 이동한 뒤, 기존 vmysql.c 파일을 백업하고 아래 코드로 교체합니다. 이 코드는 vpopmail의 표준 인증 API를 그대로 구현하며, MySQL 쿼리 대신 KeyDB의 Hash 자료구조( vpop:domain.com:user )를 읽고 씁니다. vmysql.c (KeyDB 대체용 전체 소스) C #include "vpopmail.h" #include <hiredis/hiredis.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static redisContext *rc = NULL; static struct vqpasswd vpw; static char static_pw_name[MAX_BUFF]; static char static_pw_domain[MAX_BUFF]; static char static_pw_passwd[MAX_BUFF]; static char static_pw_gecos[MAX_BUFF]; static char static_pw_dir[MAX_BUFF]; static char static_pw_shell[MAX_BUFF]; int vauth_open(unsigned update) { if (rc != NULL) return 0; rc = redisConnect("127.0.0.1", 6379); if (rc == NULL || rc->err) { if (rc) { redisFree(rc); rc = NULL; } return -1; } return 0; } void vauth_close() { if (rc != NULL) { redisFree(rc); rc = NULL; } } struct vqpasswd *vauth_getpw(char *user, char *domain) { if (vauth_open(0) != 0) return NULL; redisReply *reply = redisCommand(rc, "HMGET vpop:%s:%s pw_passwd pw_gecos pw_dir pw_shell", domain, user); if (reply == NULL || reply->type != REDIS_REPLY_ARRAY || reply->elements != 4 || reply->element[0]->type == REDIS_REPLY_NIL) { if (reply) freeReplyObject(reply); return NULL; } memset(&vpw, 0, sizeof(struct vqpasswd)); strncpy(static_pw_name, user, sizeof(static_pw_name)-1); strncpy(static_pw_domain, domain, sizeof(static_pw_domain)-1); static_pw_passwd[0] = '\0'; if (reply->element[0]->type != REDIS_REPLY_NIL) { strncpy(static_pw_passwd, reply->element[0]->str, sizeof(static_pw_passwd)-1); } static_pw_gecos[0] = '\0'; if (reply->element[1]->type != REDIS_REPLY_NIL) { strncpy(static_pw_gecos, reply->element[1]->str, sizeof(static_pw_gecos)-1); } static_pw_dir[0] = '\0'; if (reply->element[2]->type != REDIS_REPLY_NIL) { strncpy(static_pw_dir, reply->element[2]->str, sizeof(static_pw_dir)-1); } static_pw_shell[0] = '\0'; if (reply->element[3]->type != REDIS_REPLY_NIL) { strncpy(static_pw_shell, reply->element[3]->str, sizeof(static_pw_shell)-1); } vpw.pw_name = static_pw_name; vpw.pw_domain = static_pw_domain; vpw.pw_passwd = static_pw_passwd; vpw.pw_gecos = static_pw_gecos; vpw.pw_dir = static_pw_dir; vpw.pw_shell = static_pw_shell; vpw.pw_uid = VPOPMAIL_UID; vpw.pw_gid = VPOPMAIL_GID; freeReplyObject(reply); return &vpw; } int vauth_adduser(char *user, char *domain, char *password, char *gecos, char *dir) { if (vauth_open(1) != 0) return -1; redisReply *reply = redisCommand(rc, "HMSET vpop:%s:%s pw_passwd %s pw_gecos %s pw_dir %s pw_shell NOQUOTA", domain, user, password, gecos, dir); if (reply == NULL) return -1; freeReplyObject(reply); return 0; } int vauth_setpw(char *user, char *domain, char *password) { if (vauth_open(1) != 0) return -1; redisReply *reply = redisCommand(rc, "HSET vpop:%s:%s pw_passwd %s", domain, user, password); if (reply == NULL) return -1; freeReplyObject(reply); return 0; } int vauth_deluser(char *user, char *domain) { if (vauth_open(1) != 0) return -1; redisReply *reply = redisCommand(rc, "DEL vpop:%s:%s", domain, user); if (reply == NULL) return -1; freeReplyObject(reply); return 0; } int vauth_setquota(char *user, char *domain, char *quota) { if (vauth_open(1) != 0) return -1; redisReply *reply = redisCommand(rc, "HSET vpop:%s:%s pw_gecos %s", domain, user, quota); if (reply == NULL) return -1; freeReplyObject(reply); return 0; } 2. 컴파일 환경 설정 및 빌드 vpopmail이 MySQL 모듈을 빌드할 때 KeyDB용 C 코드가 컴파일되도록 하고, 링커에 hiredis 라이브러리를 추가해야 합니다. configure 실행 기존 MySQL 사용 옵션으로 configure를 돌립니다. (DB 접속 정보는 C 코드에 하드코딩되었으므로 configure의 DB 값은 무시됩니다) Bash ./configure --enable-auth-module=mysql Makefile 수정 생성된 Makefile 을 열어 LIBS 라인 끝에 -lhiredis 를 추가합니다. Makefile # Makefile 파일 내 LIBS 항목을 찾아 아래와 같이 수정 LIBS = -lcrypt -L/usr/lib/mysql -lmysqlclient -lz -lm -lhiredis 컴파일 및 설치 Bash make make install-strip 이 코드가 적용되면 vadduser 나 vchkpw 같은 vpopmail 유틸리티를 실행할 때, MySQL 서버를 전혀 호출하지 않고 KeyDB의 vpop:도메인:계정명 해시 키를 직접 조작하게 되며 POP3/IMAP 인증 속도가 월등히 상승합니다. 조미령