-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathspk_su.c
More file actions
26 lines (24 loc) · 696 Bytes
/
spk_su.c
File metadata and controls
26 lines (24 loc) · 696 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
int main(int argc, char ** const argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <package name>\n", argv[0]);
return 1;
}
const char* name = argv[1];
for (const char* s = name; *s != '\0'; ++s) {
if (!isalpha(*s) && !isdigit(*s)) {
fprintf(stderr, "Invalid package name: %s\n", name);
return 2;
}
}
char buffer[1024] = {};
snprintf(buffer, sizeof(buffer), "/bin/sed -i 's/package/root/g' /var/packages/%s/conf/privilege", name);
if (setuid(0) != 0){
perror("Error");
exit(127);
}
return system(buffer);
}