all: $(MAIN)
-repo_shell: repo_shell.c inih/ini.c git_acl.c mystrtok.c stra.c utility.c match.c version.c
+repo_shell: repo_shell.c inih/ini.c git_acl.c stringutils.c stra.c utility.c version.c
$(CC) -I inih $^ -o $@
-mystrtok_test: mystrtok_test.c mystrtok.c utility.c
+mystrtok_test: mystrtok_test.c stringutils.c utility.c
$(CC) -g $^ -o $@
-acl_test: acl_test.c git_acl.c inih/ini.c mystrtok.c stra.c utility.c match.c
+acl_test: acl_test.c git_acl.c inih/ini.c stringutils.c stra.c utility.c
$(CC) -I inih $^ -o $@
$(INFILES):%: %.in
*/
#include <stdbool.h>
-//#include <stdio.h>
-//#include <errno.h>
-//#include <stdlib.h>
-//#include <sys/types.h>
-//#include <fcntl.h>
-//#include <unistd.h>
-//#include <pwd.h>
+#include <stdlib.h>
#include <string.h>
#include "ini.h"
#include "utility.h"
-#include "mystrtok.h"
+#include "stringutils.h"
#include "stra.h"
-#include "match.h"
#include "git_acl.h"
enum {
stra_destroy(&acl->userids);
}
-static bool str_has_word(const char* string, const char* word)
-{
- char *_s = xstrdup(string);
- char *s = _s;
- char *p = my_strtok(&s, " \t\n");
-
- while (p) {
- if (match(p, word)) {
- free(_s);
- return true;
- }
- p = my_strtok(&s, " \t\n");
- }
- free(_s);
- return false;
-}
-
static int acl_handler(void* user, const char* section, const char* name,
const char* value)
{
#ifndef GIT_ACL_H
#define GIT_ACL_H
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <string.h>
-#include "ini.h"
-#include "utility.h"
-#include "mystrtok.h"
-#include "stra.h"
-
typedef enum {
PERMS_NOTFOUND = 0,
PERMS_NONE,
+++ /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 */
+++ /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.
- */
-
-/*
- * A custom strtok. This version skips any number and any combination of
- * delimiter characters between tokens.
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#include <stddef.h>
-#include <strings.h>
-
-char *my_strtok(char **begin, char* delims)
-{
- char *p;
- char *q;
-
- if (!begin)
- return NULL;
- if (!delims || !*delims || !*begin)
- return (*begin = NULL);
-
- q = *begin;
- while (*q && index(delims, *q)) q++;
- if (!*q)
- return (*begin = NULL);
- p = q;
- while (*q && !index(delims, *q)) q++;
- if (*q)
- *q++ = 0;
- *begin = q;
- return p;
-}
+++ /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.
- */
-
-/*
- * A custom strtok. This version skips any number and any combination of
- * delimiter characters between tokens.
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#ifndef MYSTRTOK_H
-#define MYSTRTOK_H
-
-char *my_strtok(char **begin, char* delims);
-
-#endif /* end of include guard: MYSTRTOK_H */
#include <stdio.h>
#include "utility.h"
-#include "mystrtok.h"
+#include "stringutils.h"
int main(int argc, char **argv)
{
#include "utility.h"
#include "version.h"
#include "git_acl.h"
+#include "stringutils.h"
#define CFG_FILE "/etc/repo_shell.cfg"
#define SHELL "/bin/bash"
#include <stdlib.h>
#include "utility.h"
+#include "stringutils.h"
#include "stra.h"
-#include "match.h"
void stra_init(stra_t *stra, size_t size)
{
--- /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.
+ */
+
+/*
+ * A custom strtok. This version skips any number and any combination of
+ * delimiter characters between tokens.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "utility.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);
+}
+
+char *my_strtok(char **begin, char* delims)
+{
+ char *p;
+ char *q;
+
+ if (!begin)
+ return NULL;
+ if (!delims || !*delims || !*begin)
+ return (*begin = NULL);
+
+ q = *begin;
+ while (*q && index(delims, *q)) q++;
+ if (!*q)
+ return (*begin = NULL);
+ p = q;
+ while (*q && !index(delims, *q)) q++;
+ if (*q)
+ *q++ = 0;
+ *begin = q;
+ return p;
+}
+
+bool str_has_word(const char* string, const char* word)
+{
+ char *_s = xstrdup(string);
+ char *s = _s;
+ char *p = my_strtok(&s, " \t\n");
+
+ while (p) {
+ if (match(p, word)) {
+ free(_s);
+ return true;
+ }
+ p = my_strtok(&s, " \t\n");
+ }
+ free(_s);
+ return false;
+}
--- /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.
+ */
+
+/*
+ * A custom strtok. This version skips any number and any combination of
+ * delimiter characters between tokens.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#ifndef MYSTRTOK_H
+#define MYSTRTOK_H
+
+#include <stdbool.h>
+
+/* Return tokens separated by any combination of contiguous characters drawn
+ * from the contents of delims. begin is the address of the pointer containing
+ * the original string on first call, and is updated during each call to skip
+ * the token already returned. Returns NULL when no more tokens are available
+ * in the string. The string pointed to by **begin is altered, as is true also
+ * with the generic strtok().
+ */
+char *my_strtok(char **begin, char* delims);
+
+/* Returns true if the word is contained within string. Words are delimited by
+ * any whitespace characters.
+ */
+bool str_has_word(const char* string, const char* word);
+
+/* Returns true if the pattern matches string. Only the asterisk character is
+ * used as a wildcard, meaning zero or more characters of any value. The
+ * wildcard, if present, may only be the last character in the pattern string.
+ */
+bool match(const char* pattern, const char* string);
+
+#endif /* end of include guard: MYSTRTOK_H */