diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-21 16:51:17 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-21 16:51:17 -0800 |
| commit | 9b121ac981bc483868fb3628ef256a78ab203557 (patch) | |
| tree | 064e0865d71944d7aaef6ea79e91c087b2d2cc6e | |
| parent | 8dc9a954f9d721bbe9bed86658e83427fb31cb84 (diff) | |
| download | tinyrad-9b121ac981bc483868fb3628ef256a78ab203557.tar.gz tinyrad-9b121ac981bc483868fb3628ef256a78ab203557.tar.bz2 tinyrad-9b121ac981bc483868fb3628ef256a78ab203557.tar.xz tinyrad-9b121ac981bc483868fb3628ef256a78ab203557.zip | |
libtinyrad: refactoring tinyrad_conf()
| -rw-r--r-- | lib/libtinyrad/lconf.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/lib/libtinyrad/lconf.c b/lib/libtinyrad/lconf.c index 29cda90..ad04db7 100644 --- a/lib/libtinyrad/lconf.c +++ b/lib/libtinyrad/lconf.c | |||
| @@ -121,8 +121,8 @@ tinyrad_conf( | |||
| 121 | TinyRadDict * dict, | 121 | TinyRadDict * dict, |
| 122 | unsigned opts ) | 122 | unsigned opts ) |
| 123 | { | 123 | { |
| 124 | const char * suffix; | 124 | const char * tinradrc; |
| 125 | const char * filename; | 125 | const char * tinyradconf; |
| 126 | char buff[4096]; | 126 | char buff[4096]; |
| 127 | char path[128]; | 127 | char path[128]; |
| 128 | const char * home; | 128 | const char * home; |
| @@ -140,37 +140,37 @@ tinyrad_conf( | |||
| 140 | // process environment variables | 140 | // process environment variables |
| 141 | tinyrad_conf_environment(tr, dict); | 141 | tinyrad_conf_environment(tr, dict); |
| 142 | 142 | ||
| 143 | // determine TINYRADRC suffix | ||
| 144 | if ((suffix = getenv("TINYRADRC")) == NULL) | ||
| 145 | suffix = "tinyradrc"; | ||
| 146 | |||
| 147 | // lookup user | 143 | // lookup user |
| 148 | getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); | 144 | getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); |
| 149 | home = (((pwres)) ? pwres->pw_dir : "/"); | 145 | home = (((pwres)) ? pwres->pw_dir : "/"); |
| 150 | 146 | ||
| 151 | // process "./${TINYRADRC}" | 147 | // determine TINYRADRC suffix |
| 152 | if ((getcwd(path, sizeof(path)))) | 148 | if ((tinradrc = getenv("TINYRADRC")) != NULL) |
| 153 | { | 149 | { |
| 154 | tinyrad_strlcat(path, "/", sizeof(path)); | 150 | // process "./${TINYRADRC}" |
| 155 | tinyrad_strlcat(path, suffix, sizeof(path)); | 151 | if ((getcwd(path, sizeof(path)))) |
| 156 | tinyrad_conf_file(tr, dict, path); | 152 | { |
| 157 | }; | 153 | tinyrad_strlcat(path, "/", sizeof(path)); |
| 154 | tinyrad_strlcat(path, tinradrc, sizeof(path)); | ||
| 155 | tinyrad_conf_file(tr, dict, path); | ||
| 156 | }; | ||
| 158 | 157 | ||
| 159 | // process "~/.{$TINYRADRC}" | 158 | // process "~/.{$TINYRADRC}" |
| 160 | tinyrad_strlcpy(path, home, sizeof(path)); | 159 | tinyrad_strlcpy(path, home, sizeof(path)); |
| 161 | tinyrad_strlcat(path, "/.", sizeof(path)); | 160 | tinyrad_strlcat(path, "/.", sizeof(path)); |
| 162 | tinyrad_strlcat(path, suffix, sizeof(path)); | 161 | tinyrad_strlcat(path, tinradrc, sizeof(path)); |
| 163 | tinyrad_conf_file(tr, dict, path); | 162 | tinyrad_conf_file(tr, dict, path); |
| 164 | 163 | ||
| 165 | // process "~/${TINYRADRC}" | 164 | // process "~/${TINYRADRC}" |
| 166 | tinyrad_strlcpy(path, home, sizeof(path)); | 165 | tinyrad_strlcpy(path, home, sizeof(path)); |
| 167 | tinyrad_strlcat(path, "/", sizeof(path)); | 166 | tinyrad_strlcat(path, "/", sizeof(path)); |
| 168 | tinyrad_strlcat(path, suffix, sizeof(path)); | 167 | tinyrad_strlcat(path, tinradrc, sizeof(path)); |
| 169 | tinyrad_conf_file(tr, dict, path); | 168 | tinyrad_conf_file(tr, dict, path); |
| 169 | }; | ||
| 170 | 170 | ||
| 171 | // process "${TINYRADCONF}" | 171 | // process "${TINYRADCONF}" |
| 172 | if ((filename = getenv("TINYRADCONF"))) | 172 | if ((tinyradconf = getenv("TINYRADCONF")) != NULL) |
| 173 | tinyrad_conf_file(tr, dict, filename); | 173 | tinyrad_conf_file(tr, dict, tinyradconf); |
| 174 | 174 | ||
| 175 | // process "./tinyradrc" | 175 | // process "./tinyradrc" |
| 176 | if ((getcwd(path, sizeof(path)))) | 176 | if ((getcwd(path, sizeof(path)))) |
