Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Allow to restrict pkg ssh to only send files withing a given directory
Baptiste Daroussin committed 13 years ago
commit 50d149c6f999577e9d79b4e51f260f9e1e874b2e
parent d461824
3 files changed +21 -0
modified libpkg/pkg.h.in
@@ -337,6 +337,7 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_EVENT_PIPE,
	PKG_CONFIG_FETCH_TIMEOUT,
	PKG_CONFIG_UNSET_TIMESTAMP,
+
	PKG_CONFIG_SSH_RESTRICT_DIR,
} pkg_config_key;

typedef enum {
modified libpkg/pkg_config.c
@@ -267,6 +267,12 @@ static struct config_entry c[] = {
		"UNSET_TIMESTAMP",
		"NO",
		NULL,
+
	},
+
	[PKG_CONFIG_SSH_RESTRICT_DIR] = {
+
		PKG_CONFIG_STRING,
+
		"SSH_RESTRICT_DIR",
+
		NULL,
+
		"Directory where the ssh subsystem will be restricted to",
	}
};

modified libpkg/ssh.c
@@ -31,6 +31,8 @@
#define _WITH_GETLINE
#include <stdio.h>
#include <string.h>
+
#include <unistd.h>
+

#include "pkg.h"

int
@@ -45,6 +47,10 @@ pkg_sshserve(void)
	const char *errstr;
	FILE *f;
	char buf[BUFSIZ];
+
	char fpath[MAXPATHLEN];
+
	const char *restricted = NULL;
+

+
	pkg_config_string(PKG_CONFIG_SSH_RESTRICT_DIR, &restricted);

	printf("ok: pkg "PKGVERSION"\n");
	for (;;) {
@@ -100,6 +106,14 @@ pkg_sshserve(void)
			continue;
		}

+
		if (restricted != NULL) {
+
			file = realpath(file, fpath);
+
			if (strncmp(file, restricted, strlen(restricted)) != 0) {
+
				printf("ko: file not found\n");
+
				continue;
+
			}
+
		}
+

		if (stat(file, &st) == -1) {
			printf("ko: file not found\n");
			continue;