From 77ae998ad35036872d99d923f0863fc5d68a12da Mon Sep 17 00:00:00 2001 From: Peer Sommerlund Date: Thu, 11 Oct 2007 16:45:07 +0100 Subject: [PATCH] cvspass-registry.p CVSNT on Windows replaces $HOME/.cvsps with registry --- cvs_direct.c | 32 ++++++++++++++++++++++++++++++++ util.c | 11 +++++++++-- util.h | 4 ++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/cvs_direct.c b/cvs_direct.c index c11f9d6..0601160 100644 --- a/cvs_direct.c +++ b/cvs_direct.c @@ -229,8 +229,13 @@ static CvsServerCtx * open_ctx_pserver(CvsServerCtx * ctx, const char * p_root) strcpy(port, "2401"); } +#ifdef __MINGW32__ + /* the line from registry does not contain port, so rebuild */ + snprintf(full_root, PATH_MAX, ":pserver:%s@%s:%s", user, server, p); +#else /* the line from .cvspass is fully qualified, so rebuild */ snprintf(full_root, PATH_MAX, ":pserver:%s@%s:%s%s", user, server, port, p); +#endif get_cvspass(pass, full_root); debug(DEBUG_TCP, "user:%s server:%s port:%s pass:%s full_root:%s", user, server, port, pass, full_root); @@ -503,6 +508,32 @@ void close_cvs_server(CvsServerCtx * ctx) static void get_cvspass(char * pass, const char * root) { +#ifdef __MINGW32__ + /* CVSNT stores password in registry HKCU\Software\Cvsnt\cvspass + * See http://issues.apache.org/bugzilla/show_bug.cgi?id=21657#c5 + * See http://www.adp-gmbh.ch/misc/tools/cvs/cvspass.html + */ + HKEY hKey; + if (RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Cvsnt\\cvspass",0,KEY_READ,&hKey)) + { + debug(DEBUG_APPERROR, "Cannot open HKCU\\Software\\Cvsnt\\cvspass registry key"); + exit(1); + } + /* "root" is connection string that require a password */ + static char buf[4096]; + DWORD dwType,dwLen; + LONG ret; + dwLen = sizeof(buf); + ret = RegQueryValueExA(hKey,root,NULL,&dwType,(LPBYTE)buf,&dwLen); + RegCloseKey(hKey); + if (ret != ERROR_SUCCESS) + { + debug(DEBUG_APPERROR, "HKCU\\Software\\Cvsnt\\cvspass registry key not readable"); + exit(1); + } + strcpy(pass,buf); /* If this function knew the size of pass, we could + use strncpy and avoid potential buffer-overflow. */ +#else char cvspass[PATH_MAX]; const char * home; FILE * fp; @@ -545,6 +576,7 @@ static void get_cvspass(char * pass, const char * root) if (!pass[0]) pass[0] = 'A'; +#endif } static void send_string(CvsServerCtx * ctx, const char * str, ...) diff --git a/util.c b/util.c index cad2abf..44e384d 100644 --- a/util.c +++ b/util.c @@ -76,13 +76,20 @@ char *get_cvsps_dir() struct stat sbuf; static char prefix[PATH_MAX]; const char * home; + const char * home_env; if (prefix[0]) return prefix; - if (!(home = getenv("HOME"))) +#ifdef __MINGW32__ + home_env = "APPDATA"; /* application data is below user's home dir */ +#else + home_env = "HOME"; +#endif + + if (!(home = getenv(home_env))) { - debug(DEBUG_APPERROR, "HOME environment variable not set"); + debug(DEBUG_APPERROR, "%s environment variable not set", home_env); exit(1); } diff --git a/util.h b/util.h index 4d85cc8..86777be 100644 --- a/util.h +++ b/util.h @@ -6,7 +6,11 @@ #ifndef UTIL_H #define UTIL_H +#ifdef __MINGW32__ +#define CVSPS_PREFIX "cvsps" +#else #define CVSPS_PREFIX ".cvsps" +#endif #ifndef PATH_MAX #define PATH_MAX 4096 -- 2.11.4.GIT