Now '*' can be used as the last character of a userid or repoid target.
Such as:
[user_groups]
group = st* sm*
[repo_groups]
rgroup = mirrors/*
[repo oss*]
* = rw
all: $(MAIN)
-repo_shell: repo_shell.c inih/ini.c git_acl.c mystrtok.c stra.c utility.c version.c
+repo_shell: repo_shell.c inih/ini.c git_acl.c mystrtok.c stra.c utility.c match.c version.c
$(CC) -I inih $^ -o $@
mystrtok_test: mystrtok_test.c mystrtok.c utility.c
$(CC) -g $^ -o $@
-acl_test: acl_test.c git_acl.c inih/ini.c mystrtok.c stra.c utility.c
+acl_test: acl_test.c git_acl.c inih/ini.c mystrtok.c stra.c utility.c match.c
$(CC) -I inih $^ -o $@
$(INFILES):%: %.in
#include "utility.h"
#include "mystrtok.h"
#include "stra.h"
+#include "match.h"
#include "git_acl.h"
-#define ANYID "*"
-
enum {
DFLT_IDS_SZ = 32
};
char *p = my_strtok(&s, " \t\n");
while (p) {
- if (!strcmp(p, word) || !strcmp(p, ANYID)) {
+ if (match(p, word)) {
free(_s);
return true;
}
if (!repo || my_strtok(&p, " \t\n"))
die("acl_handler: badly formatted section '%s'", section);
/* repo is repo name, name is userid, value is permission */
- if ((!strcmp(repo, ANYID) || stra_find(&acl->repoids, repo) >= 0) &&
- (!strcmp(name, ANYID) || stra_find(&acl->userids, name) >= 0)) {
+ if (stra_match(&acl->repoids, repo) >= 0 &&
+ stra_match(&acl->userids, name) >= 0) {
acl->perms = perms_from_str(value);
set_lm_repoid(repo);
set_lm_userid(name);
allusers = *
[repo_groups]
+mirrors = mirror/*
public = oss-web.git repo_shell.git cp210x.git
private = redmine.git nesc.git
+[repo oss*]
+steve = rw
+
+[repo mirrors]
+jobu=rw
+devs=r
+
[repo nesc.git]
steve = r
devs = rw
--- /dev/null
+/*
+ * Copyright © 2012, Titanium Mirror, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of
+ * Titanium Mirror, Inc. All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of
+ * Titanium Mirror, Inc.
+ */
+
+/*
+ * Match allowing wildcard ('*')
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#include <stdbool.h>
+#include <string.h>
+
+bool match(const char* pattern, const char* string)
+{
+ char* p;
+
+ if (!pattern || !string)
+ return false;
+ p = index(pattern, '*');
+ if (p == pattern)
+ return true;
+ else if (p)
+ return (strncmp(pattern, string, p - pattern) == 0);
+ else
+ return (strcmp(pattern, string) == 0);
+}
--- /dev/null
+/*
+ * Copyright © 2012, Titanium Mirror, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of
+ * Titanium Mirror, Inc. All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of
+ * Titanium Mirror, Inc.
+ */
+
+/*
+ * Match allowing wildcard ('*')
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#ifndef MATCH_H
+#define MATCH_H
+
+#include <stdbool.h>
+
+bool match(const char* pattern, const char* string);
+
+#endif /* end of include guard: MATCH_H */
return 0;
}
- prog = xstrdup(argv[2]);
- if (!strncmp(prog, "git", 3) && isspace(prog[3]))
- /* Accept "git foo" as if the caller said "git-foo". */
- prog[3] = '-';
-
- for (cmd = cmd_list ; cmd->name ; cmd++) {
- int len = strlen(cmd->name);
- char *arg;
- struct passwd *pw;
- if (strncmp(cmd->name, prog, len))
- continue;
- arg = NULL;
- switch (prog[len]) {
- case '\0':
+ if (argc == 3) {
+ /* argv[0] = repo_shell, argv[1] = -c, argv[2] = cmd
+ * cmd = "svnserve -t" or "git-xxx '/path/to/repo.git'"
+ */
+ prog = xstrdup(argv[2]);
+ if (!strncmp(prog, "git", 3) && isspace(prog[3]))
+ /* Accept "git foo" as if the caller said "git-foo". */
+ prog[3] = '-';
+
+ for (cmd = cmd_list ; cmd->name ; cmd++) {
+ int len = strlen(cmd->name);
+ char *arg;
+ struct passwd *pw;
+ if (strncmp(cmd->name, prog, len))
+ continue;
arg = NULL;
- break;
- case ' ':
- arg = prog + len + 1;
- break;
- default:
- continue;
+ switch (prog[len]) {
+ case '\0':
+ arg = NULL;
+ break;
+ case ' ':
+ arg = prog + len + 1;
+ break;
+ default:
+ continue;
+ }
+
+ pw = getpwuid(getuid());
+ exit(cmd->exec(cmd->name, arg, pw->pw_name));
}
-
- pw = getpwuid(getuid());
- exit(cmd->exec(cmd->name, arg, pw->pw_name));
}
if (!check_ssh_interactive(getuid()))
#include <stdlib.h>
#include "utility.h"
#include "stra.h"
+#include "match.h"
void stra_init(stra_t *stra, size_t size)
{
return stra->count++;
}
+int stra_match(stra_t *stra, const char *item)
+{
+ unsigned i;
+
+ if (!stra)
+ die("stra_in: stra NULL reference");
+ if (!item)
+ die("stra_in: item is NULL");
+ for (i = 0; i < stra->count; i++) {
+ if (match(item, stra->items[i]))
+ return i;
+ }
+ return -1;
+}
+
int stra_find(stra_t *stra, const char *item)
{
unsigned i;
/* Add an item to the end of the string array, returning its ele# */
int stra_add(stra_t *stra, const char *item);
+/* Return the ele# of the first string matching item, which may have * */
+int stra_match(stra_t *stra, const char *item);
+
/* Return the ele# of the first string matching item */
int stra_find(stra_t *stra, const char *item);