#define CFG_FILE "/etc/repo_shell.cfg"
#define GIT_ACL_FILE "git_acl.cfg"
+#define SHELL "/bin/bash"
typedef struct {
char *svn_root;
char *owner;
} cfg_t;
-static const char* shell_argv[] = { "/bin/bash", NULL };
-
#undef USE_DEFAULTS
#ifdef USE_DEFAULTS /* perhaps we want defaults? Not sure */
static cfg_t cfg {
static cfg_t cfg;
#endif
-#define alloc_nr(x) (((x)+16)*3/2)
-
-/*
- * Realloc the buffer pointed at by variable 'x' so that it can hold
- * at least 'nr' entries; the number of entries currently allocated
- * is 'alloc', using the standard growing factor alloc_nr() macro.
- *
- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
- */
-#define ALLOC_GROW(x, nr, alloc) \
- do { \
- if ((nr) > alloc) { \
- if (alloc_nr(alloc) < (nr)) \
- alloc = (nr); \
- else \
- alloc = alloc_nr(alloc); \
- x = xrealloc((x), alloc * sizeof(*(x))); \
- } \
- } while (0)
-
-static inline void die(const char *fmt, ...)
+static void die(const char *fmt, ...)
{
va_list ap;
return ret;
}
-void *xrealloc(void *ptr, size_t size)
-{
- void *ret;
-
- ret = realloc(ptr, size);
- if (!ret && !size)
- ret = realloc(ptr, 1);
- if (!ret)
- die("Out of memory, realloc failed");
- return ret;
-}
-
static uid_t user_uid(char *user)
{
struct passwd *pw = getpwnam(user);
* access, a return of 1 means read only, and a return of 2 means
* read/write.
*/
+#if 0
struct passwd *pw;
char *file;
int len = strlen(cfg.owner) + strlen(GIT_ACL_FILE) + 8;
len = strlen(pw->pw_dir) + strlen(GIT_ACL_FILE) + 2;
file = xmalloc(sizeof(char) * len);
sprintf(file, "%s/%s", pw->pw_dir, GIT_ACL_FILE);
- fprintf(stderr, "[someday check %s]\n", file);
+ fprintf(stderr, "[someday check %s for git ACLs]\n", file);
free(file);
+#endif
return 2; /* assume read/write for now */
}
return execvp(svnserve_argv[0], (char *const *) svnserve_argv);
}
-#define SPLIT_CMDLINE_BAD_ENDING 1
-#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
-static const char *split_cmdline_errors[] = {
- "cmdline ends with \\",
- "unclosed quote"
-};
-
-int split_cmdline(char *cmdline, const char ***argv)
-{
- int src, dst, count = 0, size = 16;
- char quoted = 0;
-
- *argv = xmalloc(sizeof(char *) * size);
-
- /* split alias_string */
- (*argv)[count++] = cmdline;
- for (src = dst = 0; cmdline[src];) {
- char c = cmdline[src];
- if (!quoted && isspace(c)) {
- cmdline[dst++] = 0;
- while (cmdline[++src]
- && isspace(cmdline[src]))
- ; /* skip */
- ALLOC_GROW(*argv, count+1, size);
- (*argv)[count++] = cmdline + dst;
- } else if (!quoted && (c == '\'' || c == '"')) {
- quoted = c;
- src++;
- } else if (c == quoted) {
- quoted = 0;
- src++;
- } else {
- if (c == '\\' && quoted != '\'') {
- src++;
- c = cmdline[src];
- if (!c) {
- free(*argv);
- *argv = NULL;
- return -SPLIT_CMDLINE_BAD_ENDING;
- }
- }
- cmdline[dst++] = c;
- src++;
- }
- }
-
- cmdline[dst] = 0;
-
- if (quoted) {
- free(*argv);
- *argv = NULL;
- return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
- }
-
- ALLOC_GROW(*argv, count+1, size);
- (*argv)[count] = NULL;
-
- return count;
-}
-
-const char *split_cmdline_strerror(int split_cmdline_errno) {
- return split_cmdline_errors[-split_cmdline_errno-1];
-}
-
static void cd_to_homedir(void)
{
const char *home = getenv("HOME");
if (argc == 1 && check_ssh_interactive(getuid())) {
setuid(getuid());
- execvp(shell_argv[0], (char *const *) shell_argv);
- }
+ argv[0] = SHELL;
+ execvp(argv[0], (char *const *) argv);
+ }
#ifdef USE_DEFAULTS
ini_parse("repo_shell.cfg", handler, &cfg);
setuid(getuid());
cd_to_homedir();
- count = split_cmdline(prog, &user_argv);
- if (count >= 0) {
- execvp(user_argv[0], (char *const *) user_argv);
- free(user_argv);
- die("unrecognized command '%s'", argv[2]);
- } else {
- free(prog);
- die("invalid command format '%s': %s", argv[2],
- split_cmdline_strerror(count));
- }
+ argv[0] = SHELL;
+ execvp(argv[0], (char *const *) argv);
}