From f5bfafe26994139c8537a19c3f1d18d32a40c628 Mon Sep 17 00:00:00 2001 From: sw1tchbl4d3 Date: Tue, 13 Jul 2021 23:21:34 +0200 Subject: [PATCH] Add config for rdo This is needed for #1. --- Makefile | 5 +++-- README.md | 4 +--- rdo.c | 31 +++++++++++++++++++++++++------ rdo_sample.conf | 1 + 4 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 rdo_sample.conf diff --git a/Makefile b/Makefile index fb12210..4cb309f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 76d3055..dfc9955 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/rdo.c b/rdo.c index 4e6f588..edf6340 100644 --- a/rdo.c +++ b/rdo.c @@ -7,13 +7,34 @@ #include #include +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