only cosmetic changes to make the compiler happy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
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;
}