[pacman-dev,2/2] pacman: Add XferClientCert and XferClientKey options.

Message ID 20181114163714.7318-2-maarten@de-vri.es
State New
Headers show
Series
  • [pacman-dev,1/2] libalpm: Add dlclientcert and dlclientkey options.
Related show

Commit Message

Maarten de Vries Nov. 14, 2018, 4:37 p.m. UTC
---
 etc/pacman.conf.in |  2 ++
 src/pacman/conf.c  | 22 ++++++++++++++++++++++
 src/pacman/conf.h  |  2 ++
 3 files changed, 26 insertions(+)

Patch

diff --git a/etc/pacman.conf.in b/etc/pacman.conf.in
index 8e967fbb..3285e8ae 100644
--- a/etc/pacman.conf.in
+++ b/etc/pacman.conf.in
@@ -16,6 +16,8 @@ 
 #GPGDir      = @sysconfdir@/pacman.d/gnupg/
 #HookDir     = @sysconfdir@/pacman.d/hooks/
 HoldPkg     = pacman glibc
+#XferClientCert = /root/certificate.pem
+#XferClientKey  = /root/key.pem
 #XferCommand = /usr/bin/curl -L -C - -f -o %o %u
 #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
 #CleanMethod = KeepInstalled
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 29f69052..63380650 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -150,6 +150,8 @@  int config_free(config_t *oldconfig)
 	free(oldconfig->gpgdir);
 	FREELIST(oldconfig->hookdirs);
 	FREELIST(oldconfig->cachedirs);
+	free(oldconfig->xferclientcert);
+	free(oldconfig->xferclientkey);
 	free(oldconfig->xfercommand);
 	free(oldconfig->print_format);
 	free(oldconfig->arch);
@@ -567,6 +569,12 @@  static int _parse_options(const char *key, char *value,
 				config->logfile = strdup(value);
 				pm_printf(ALPM_LOG_DEBUG, "config: logfile: %s\n", value);
 			}
+		} else if(strcmp(key, "XferClientCert") == 0) {
+			config->xferclientcert = strdup(value);
+			pm_printf(ALPM_LOG_DEBUG, "config: xferclientcert: %s\n", value);
+		} else if(strcmp(key, "XferClientKey") == 0) {
+			config->xferclientkey = strdup(value);
+			pm_printf(ALPM_LOG_DEBUG, "config: xferclientkey: %s\n", value);
 		} else if(strcmp(key, "XferCommand") == 0) {
 			config->xfercommand = strdup(value);
 			pm_printf(ALPM_LOG_DEBUG, "config: xfercommand: %s\n", value);
@@ -753,6 +761,20 @@  static int setup_libalpm(void)
 		register_repo(i->data);
 	}
 
+	ret = alpm_option_set_dlclientcert(handle, config->xferclientcert);
+	if(ret != 0) {
+		pm_printf(ALPM_LOG_ERROR, _("problem setting dlclientcert '%s' (%s)\n"),
+				config->xferclientcert, alpm_strerror(alpm_errno(handle)));
+		return ret;
+	}
+
+	ret = alpm_option_set_dlclientkey(handle, config->xferclientkey);
+	if(ret != 0) {
+		pm_printf(ALPM_LOG_ERROR, _("problem setting dlclientkey '%s' (%s)\n"),
+				config->xferclientkey, alpm_strerror(alpm_errno(handle)));
+		return ret;
+	}
+
 	if(config->xfercommand) {
 		alpm_option_set_fetchcb(handle, download_with_xfercommand);
 	} else if(!(alpm_capabilities() & ALPM_CAPABILITY_DOWNLOADER)) {
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index ababf2e0..c7a426da 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -125,6 +125,8 @@  typedef struct __config_t {
 	alpm_list_t *noupgrade;
 	alpm_list_t *noextract;
 	alpm_list_t *overwrite_files;
+	char *xferclientcert;
+	char *xferclientkey;
 	char *xfercommand;
 
 	/* our connection to libalpm */