Add config for rdo

This is needed for #1.
This commit is contained in:
sw1tchbl4d3 2021-07-13 23:21:34 +02:00
parent 3e4ffde3a4
commit f5bfafe269
4 changed files with 30 additions and 11 deletions

View file

@ -6,10 +6,11 @@ install: rdo
chown root:root /usr/bin/rdo
chmod 755 /usr/bin/rdo
chmod u+s /usr/bin/rdo
mkdir -p /etc/rdo
cp rdo_sample.conf /etc/rdo.conf
uninstall:
rm /usr/bin/rdo
rm -rf /etc/rdo
rm /etc/rdo.conf
clean:
rm rdo

View file

@ -12,9 +12,7 @@ sudo make install
```
After that, you'll have to configure rdo to allow you to use it.
```sh
echo "YourUsername" | sudo tee /etc/rdo/username
```
To do this, edit `/etc/rdo.conf`, and set the username variable to your own.
After that you're good to go!

31
rdo.c
View file

@ -7,13 +7,34 @@
#include <string.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) {
for(int i=0; i<argc; i++)
argv[i] = argv[i + 1];
setuid(0);
setgid(0);
if (execvp(argv[0], argv) != 0)
perror(argv[0]);
}
@ -22,10 +43,10 @@ int main(int argc, char** argv) {
if (argc < 2)
errx(1, "Please specify a program to run");
FILE* fp = fopen("/etc/rdo/username", "r");
FILE* fp = fopen("/etc/rdo.conf", "r");
if (!fp)
err(1, "Could not open /etc/rdo/username");
err(1, "Could not open /etc/rdo.conf");
int ruid = getuid();
if (ruid == 0) {
@ -35,9 +56,7 @@ int main(int argc, char** argv) {
}
char username[64];
fgets(username, 64, fp);
fclose(fp);
username[strcspn(username, "\n")] = 0;
getconf(fp, "username", username, sizeof(username));
struct passwd* p = getpwnam(username);
if (!p)

1
rdo_sample.conf Normal file
View file

@ -0,0 +1 @@
username=sw1tchbl4d3