-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestricted_sh.c
80 lines (75 loc) · 1.36 KB
/
restricted_sh.c
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
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
int cat_pam(const char *path)
{
FILE *fi;
int c;
if ((fi = fopen(path, "r")) == NULL)
return 1;
while ((c = getc(fi)) != EOF) {
if (c == '%') {
if ((c = getc(fi)) == EOF)
break;
switch(c) {
case 'u':
{
struct passwd *pw;
uid_t uid;
uid = getuid();
pw = getpwuid(uid);
if (pw)
printf("%s", pw->pw_name);
}
break;
case 'h':
{
char hostname[65];
gethostname(hostname, sizeof hostname);
printf("%s", hostname);
}
break;
default:
putchar('%');
case '%':
putchar(c);
}
} else {
putchar(c);
}
}
fclose(fi);
return 0;
}
int main(int argc, char *argv[]) {
if (argc == 3 && strncmp("git-lfs-authenticate", argv[2], 20) == 0
&& (argv[2][20] == '\0' || argv[2][20] == ' ')) {
char *new_arg[4] = { NULL };
char *a;
int p, q;
a = argv[2];
p = 1;
q = 0;
new_arg[0] = a;
while (*a != '\0' && p < 4) {
if (*a == '"' && q) {
q--;
*a = '\0';
} else if (*a == ' ' && !q) {
*a = '\0';
if (a[1] == '"') {
new_arg[p++] = a+2;
q = 2;
}
else
new_arg[p++] = a+1;
}
a++;
}
execvpe("/usr/local/bin/git-lfs-authenticate", new_arg, NULL);
}
return cat_pam("/opt/git_lfs_server/info.txt");
}