forked from soccera/rdo
parent
3e4ffde3a4
commit
f5bfafe269
4 changed files with 30 additions and 11 deletions
5
Makefile
5
Makefile
|
@ -6,10 +6,11 @@ install: rdo
|
||||||
chown root:root /usr/bin/rdo
|
chown root:root /usr/bin/rdo
|
||||||
chmod 755 /usr/bin/rdo
|
chmod 755 /usr/bin/rdo
|
||||||
chmod u+s /usr/bin/rdo
|
chmod u+s /usr/bin/rdo
|
||||||
mkdir -p /etc/rdo
|
cp rdo_sample.conf /etc/rdo.conf
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm /usr/bin/rdo
|
rm /usr/bin/rdo
|
||||||
rm -rf /etc/rdo
|
rm /etc/rdo.conf
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm rdo
|
rm rdo
|
||||||
|
|
|
@ -12,9 +12,7 @@ sudo make install
|
||||||
```
|
```
|
||||||
|
|
||||||
After that, you'll have to configure rdo to allow you to use it.
|
After that, you'll have to configure rdo to allow you to use it.
|
||||||
```sh
|
To do this, edit `/etc/rdo.conf`, and set the username variable to your own.
|
||||||
echo "YourUsername" | sudo tee /etc/rdo/username
|
|
||||||
```
|
|
||||||
|
|
||||||
After that you're good to go!
|
After that you're good to go!
|
||||||
|
|
||||||
|
|
31
rdo.c
31
rdo.c
|
@ -7,13 +7,34 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <bsd/readpassphrase.h>
|
#include <bsd/readpassphrase.h>
|
||||||
|
|
||||||
|
int getconf(FILE* fp, const char* entry, char* result, size_t len_result) {
|
||||||
|
char* line = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
|
while (getline(&line, &len, fp) != -1) {
|
||||||
|
if (strncmp(entry, line, strlen(entry)) == 0) {
|
||||||
|
strtok(line, "=");
|
||||||
|
char* token = strtok(NULL, "=");
|
||||||
|
if (token) {
|
||||||
|
strncpy(result, token, len_result);
|
||||||
|
result[strcspn(result, "\n")] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void runprog(int argc, char** argv) {
|
void runprog(int argc, char** argv) {
|
||||||
for(int i=0; i<argc; i++)
|
for(int i=0; i<argc; i++)
|
||||||
argv[i] = argv[i + 1];
|
argv[i] = argv[i + 1];
|
||||||
|
|
||||||
setuid(0);
|
setuid(0);
|
||||||
setgid(0);
|
setgid(0);
|
||||||
|
|
||||||
if (execvp(argv[0], argv) != 0)
|
if (execvp(argv[0], argv) != 0)
|
||||||
perror(argv[0]);
|
perror(argv[0]);
|
||||||
}
|
}
|
||||||
|
@ -22,10 +43,10 @@ int main(int argc, char** argv) {
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
errx(1, "Please specify a program to run");
|
errx(1, "Please specify a program to run");
|
||||||
|
|
||||||
FILE* fp = fopen("/etc/rdo/username", "r");
|
FILE* fp = fopen("/etc/rdo.conf", "r");
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
err(1, "Could not open /etc/rdo/username");
|
err(1, "Could not open /etc/rdo.conf");
|
||||||
|
|
||||||
int ruid = getuid();
|
int ruid = getuid();
|
||||||
if (ruid == 0) {
|
if (ruid == 0) {
|
||||||
|
@ -35,9 +56,7 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char username[64];
|
char username[64];
|
||||||
fgets(username, 64, fp);
|
getconf(fp, "username", username, sizeof(username));
|
||||||
fclose(fp);
|
|
||||||
username[strcspn(username, "\n")] = 0;
|
|
||||||
|
|
||||||
struct passwd* p = getpwnam(username);
|
struct passwd* p = getpwnam(username);
|
||||||
if (!p)
|
if (!p)
|
||||||
|
|
1
rdo_sample.conf
Normal file
1
rdo_sample.conf
Normal file
|
@ -0,0 +1 @@
|
||||||
|
username=sw1tchbl4d3
|
Loading…
Add table
Reference in a new issue