Commit 35d62769bc7b5e5f5d03d7eedfc14340a5dcccc0

Thomas de Grivel 2013-07-27T02:00:55

only cosmetic changes to make the compiler happy

diff --git a/Makefile b/Makefile
index da24ac5..64cc50a 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@
 ##
 
 PROG =	git-auth
-VER = 0.2
+VER = 0.2.1
 
 GIT_SHELL ?= /usr/local/bin/git-shell
 
diff --git a/git-auth.c b/git-auth.c
index 8cbac96..063bbca 100644
--- a/git-auth.c
+++ b/git-auth.c
@@ -39,7 +39,7 @@
 
 s_sympackage g_sympkg;
 
-void stracat (char *buf, size_t bufsiz, const char **str_array, size_t sasiz)
+static void stracat (char *buf, size_t bufsiz, const char **str_array, size_t sasiz)
 {
   size_t b = 0;
   size_t a;
@@ -54,14 +54,14 @@ void stracat (char *buf, size_t bufsiz, const char **str_array, size_t sasiz)
   }
 }
 
-void log_args (const char *op, int argc, const char **argv)
+static void log_args (const char *op, int argc, const char **argv)
 {
   char msg[2048];
   stracat(msg, sizeof(msg), argv, argc);
   syslog(LOG_INFO, "%s %s", op, msg);
 }
 
-void log_rule (const char *op, s_symtable *cmd)
+static void log_rule (const char *op, s_symtable *cmd)
 {
   char msg[2048];
   size_t m = 0;
@@ -72,7 +72,7 @@ void log_rule (const char *op, s_symtable *cmd)
   syslog(LOG_INFO, "%s %s", op, msg);
 }
 
-void log_cmd (const char *op, s_symtable *cmd)
+static void log_cmd (const char *op, s_symtable *cmd)
 {
   char msg[2048];
   assert(cmd);
@@ -80,7 +80,7 @@ void log_cmd (const char *op, s_symtable *cmd)
   syslog(LOG_INFO, "%s %s", op, msg);
 }
 
-t_sym read_symbol (const char **buf)
+static t_sym read_symbol (const char **buf)
 {
   const char *b = *buf;
   const char *start;
@@ -94,7 +94,7 @@ t_sym read_symbol (const char **buf)
     sympackage_intern_n(&g_sympkg, start, b - start);
 }
 
-void rule_read (s_rule *r, const char *buf)
+static void rule_read (s_rule *r, const char *buf)
 {
   const char *b = buf;
   t_sym s;
@@ -104,15 +104,16 @@ void rule_read (s_rule *r, const char *buf)
   }
 }
 
-void rules_read (s_rules *rr, const char *path)
+static void rules_read (s_rules *rr, const char *path)
 {
+  FILE *fp;
+  char line[2048];
   syslog(LOG_DEBUG, "READ %s", path);
-  FILE *fp = fopen(path, "r");
+  fp = fopen(path, "r");
   if (!fp) {
     syslog(LOG_ERR, "rules_read: %s: %s", path, strerror(errno));
     err(3, "rules_read: %s", path);
   }
-  char line[2048];
   while (fgets(line, sizeof(line) - 4, fp)) {
     s_rule r;
     syslog(LOG_DEBUG, "LINE %s", line);
@@ -133,29 +134,31 @@ void rules_read (s_rules *rr, const char *path)
   fclose(fp);
 }
 
-int rule_match (s_rule *r, s_symtable *cmd)
+static int rule_match (s_rule *r, s_symtable *cmd)
 {
   assert(r);
   assert(cmd);
   if (r->count > cmd->count)
     return 0;
-  size_t i = r->count;
-  t_sym *rs = r->sym;
-  t_sym *cs = cmd->sym;
-  static t_sym sym_wild = 0;
-  if (!sym_wild)
-    sym_wild = sympackage_intern_static(&g_sympkg, "*");
-  while (i--) {
-    if (*rs != sym_wild && *rs != *cs)
-      return 0;
-    syslog(LOG_DEBUG, "%s %s", *rs, *cs);
-    rs++;
-    cs++;
+  {
+    size_t i = r->count;
+    t_sym *rs = r->sym;
+    t_sym *cs = cmd->sym;
+    static t_sym sym_wild = 0;
+    if (!sym_wild)
+      sym_wild = sympackage_intern_static(&g_sympkg, "*");
+    while (i--) {
+      if (*rs != sym_wild && *rs != *cs)
+	return 0;
+      syslog(LOG_DEBUG, "%s %s", *rs, *cs);
+      rs++;
+      cs++;
+    }
   }
   return 1;
 }
 
-int auth (s_rules *rr, s_symtable *cmd)
+static int auth (s_rules *rr, s_symtable *cmd)
 {
   size_t i = rr->count;
   s_rule *r = rr->rule;
@@ -167,39 +170,39 @@ int auth (s_rules *rr, s_symtable *cmd)
   return 0;
 }
 
-void init_package ()
+static void init_package (void)
 {
   sympackage_init(&g_sympkg);
   sympackage_intern_static(&g_sympkg, "*");
 }
 
-void usage (const char *argv0)
+static void usage (const char *argv0)
 {
   fprintf(stderr, "Usage: %s=ID %s -c COMMAND\n", ENV_AUTH_ID, argv0);
   exit(5);
 }
 
-void cmd_init (s_symtable *cmd, t_sym id, const char *arg)
+static void cmd_init (s_symtable *cmd, t_sym id, const char *arg)
 {
   rule_init(cmd);
   rule_add(cmd, id);
   rule_read(cmd, arg);
 }
 
-void cleanup ()
+static void cleanup (void)
 {
   closelog();
   sympackage_free(&g_sympkg);
 }
 
-void exec_cmd (const s_symtable *cmd)
+static void exec_cmd (const s_symtable *cmd)
 {
   s_symtable xc;
+  char buf[2048];
   assert(cmd);
   symtable_init(&xc);
   symtable_add(&xc, SHELL);
   symtable_add(&xc, "-c");
-  char buf[2048];
   stracat(buf, sizeof(buf), cmd->sym + 1, cmd->count - 1);
   symtable_add(&xc, buf);
   log_cmd("EXEC", &xc);
@@ -221,20 +224,24 @@ int main (int argc, char **argv)
   openlog(argv[0], LOG_PID, LOG_AUTH);
   log_args("NEW", argc, (const char **)argv);
   init_package();
-  const char *env_auth_id = getenv(ENV_AUTH_ID);
-  t_sym id = sympackage_intern(&g_sympkg, env_auth_id ? env_auth_id : "");
-  s_symtable cmd;
-  cmd_init(&cmd, id, argv[2]);
-  rules_init(&rr);
-  rules_read(&rr, "/etc/git-auth.conf");
-  int auth_ok = auth(&rr, &cmd);
-  rules_free(&rr);
-  log_rule(auth_ok ? "ALLOW" : "DENY", &cmd);
-  if (auth_ok) {
-    exec_cmd(&cmd);
-    // never reached
+  {
+    const char *env_auth_id = getenv(ENV_AUTH_ID);
+    t_sym id = sympackage_intern(&g_sympkg, env_auth_id ? env_auth_id : "");
+    s_symtable cmd;
+    cmd_init(&cmd, id, argv[2]);
+    rules_init(&rr);
+    rules_read(&rr, "/etc/git-auth.conf");
+    {
+      int auth_ok = auth(&rr, &cmd);
+      rules_free(&rr);
+      log_rule(auth_ok ? "ALLOW" : "DENY", &cmd);
+      if (auth_ok) {
+	exec_cmd(&cmd);
+	// never reached
+      }
+    }
+    log_rule("DENY", &cmd);
   }
-  log_rule("DENY", &cmd);
   cleanup();
   return 1;
 }
diff --git a/rule.c b/rule.c
index 8a5adbe..d73cd31 100644
--- a/rule.c
+++ b/rule.c
@@ -32,8 +32,9 @@ void rules_init (s_rules *rr)
 
 void rules_free (s_rules *rr)
 {
+  int i;
   assert(rr);
-  int i = rr->count;
+  i = rr->count;
   while (i--)
     rule_free(rr->rule + i);
   free(rr->rule);
diff --git a/sympackage.c b/sympackage.c
index fd82c9a..171a146 100644
--- a/sympackage.c
+++ b/sympackage.c
@@ -36,8 +36,9 @@ void sympackage_free (s_sympackage *sp)
 
 t_sym sympackage_intern (s_sympackage *sp, const char *string)
 {
+  t_sym s;
   assert(sp);
-  t_sym s = symtable_find(&sp->static_table, string);
+  s = symtable_find(&sp->static_table, string);
   if (!s)
     s = symtable_find(&sp->dynamic_table, string);
   if (!s)
@@ -47,8 +48,9 @@ t_sym sympackage_intern (s_sympackage *sp, const char *string)
 
 t_sym sympackage_intern_n (s_sympackage *sp, const char *string, size_t len)
 {
+  t_sym s;
   assert(sp);
-  t_sym s = symtable_find_n(&sp->static_table, string, len);
+  s = symtable_find_n(&sp->static_table, string, len);
   if (!s)
     s = symtable_find_n(&sp->dynamic_table, string, len);
   if (!s)
@@ -58,8 +60,9 @@ t_sym sympackage_intern_n (s_sympackage *sp, const char *string, size_t len)
 
 t_sym sympackage_intern_static (s_sympackage *sp, const char *string)
 {
+  t_sym s;
   assert(sp);
-  t_sym s = symtable_find(&sp->static_table, string);
+  s = symtable_find(&sp->static_table, string);
   if (!s)
     s = symtable_add(&sp->static_table, string);
   return s;
diff --git a/symtable.c b/symtable.c
index 3a3c301..67b0038 100644
--- a/symtable.c
+++ b/symtable.c
@@ -52,9 +52,11 @@ void symtable_free (s_symtable *st)
 void symtable_free_all (s_symtable *st)
 {
   assert(st);
-  int i = st->count;
-  while (i--)
-    free((void*)st->sym[i]);
+  {
+    int i = st->count;
+    while (i--)
+      free((void*)st->sym[i]);
+  }
   free(st->sym);
   bzero(st, sizeof(s_symtable));
 }
@@ -71,17 +73,19 @@ void symtable_enlarge (s_symtable *st)
 t_sym symtable_find (s_symtable *st, const char *string)
 {
   assert(st);
-  t_sym *s = st->sym;
-  int i = st->count;
-  while (i--) {
-    if ((*s == string) || (string && !strcmp(string, *s)))
-      return *s;
-    s++;
+  {
+    t_sym *s = st->sym;
+    int i = st->count;
+    while (i--) {
+      if ((*s == string) || (string && !strcmp(string, *s)))
+	return *s;
+      s++;
+    }
   }
   return NULL;
 }
 
-int strcmp_n (const char *a, const char *b, size_t len_b)
+static int strcmp_n (const char *a, const char *b, size_t len_b)
 {
   const unsigned char *aa = (const unsigned char *) a;
   const unsigned char *bb = (const unsigned char *) b;
@@ -100,12 +104,14 @@ int strcmp_n (const char *a, const char *b, size_t len_b)
 t_sym symtable_find_n (s_symtable *st, const char *string, size_t len)
 {
   assert(st);
-  t_sym *s = st->sym;
-  int i = st->count;
-  while (i--) {
-    if (*s == string || (string && len && !strcmp_n(*s, string, len)))
-      return *s;
-    s++;
+  {
+    t_sym *s = st->sym;
+    int i = st->count;
+    while (i--) {
+      if (*s == string || (string && len && !strcmp_n(*s, string, len)))
+	return *s;
+      s++;
+    }
   }
   return NULL;
 }