diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-18 00:27:25 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-18 00:27:25 -0800 |
| commit | 306c35084c0a71466ada96f878a335e5edac0cbb (patch) | |
| tree | e625d47cd58ed3f5740ea768e68a46dd9b51c4b1 | |
| parent | 71aacd9a68940af857b34ddcddeb9ce388002f6d (diff) | |
| download | tinyrad-306c35084c0a71466ada96f878a335e5edac0cbb.tar.gz tinyrad-306c35084c0a71466ada96f878a335e5edac0cbb.tar.bz2 tinyrad-306c35084c0a71466ada96f878a335e5edac0cbb.tar.xz tinyrad-306c35084c0a71466ada96f878a335e5edac0cbb.zip | |
libtinyrad: updating config file order in tinyrad_conf()
| -rw-r--r-- | lib/libtinyrad/lconf.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/libtinyrad/lconf.c b/lib/libtinyrad/lconf.c index 55f4709..3f9d2fb 100644 --- a/lib/libtinyrad/lconf.c +++ b/lib/libtinyrad/lconf.c | |||
| @@ -123,9 +123,9 @@ tinyrad_conf( | |||
| 123 | { | 123 | { |
| 124 | const char * suffix; | 124 | const char * suffix; |
| 125 | const char * filename; | 125 | const char * filename; |
| 126 | const char * prefix; | ||
| 127 | char buff[4096]; | 126 | char buff[4096]; |
| 128 | char path[128]; | 127 | char path[128]; |
| 128 | const char * home; | ||
| 129 | struct passwd pwd; | 129 | struct passwd pwd; |
| 130 | struct passwd * pwres; | 130 | struct passwd * pwres; |
| 131 | 131 | ||
| @@ -144,7 +144,11 @@ tinyrad_conf( | |||
| 144 | if ((suffix = getenv("TINYRADRC")) == NULL) | 144 | if ((suffix = getenv("TINYRADRC")) == NULL) |
| 145 | suffix = "tinyradrc"; | 145 | suffix = "tinyradrc"; |
| 146 | 146 | ||
| 147 | // search current directory | 147 | // lookup user |
| 148 | getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); | ||
| 149 | home = (((pwres)) ? pwres->pw_dir : "/"); | ||
| 150 | |||
| 151 | // process "./${TINYRADRC}" | ||
| 148 | if ((getcwd(path, sizeof(path)))) | 152 | if ((getcwd(path, sizeof(path)))) |
| 149 | { | 153 | { |
| 150 | tinyrad_strlcat(path, "/", sizeof(path)); | 154 | tinyrad_strlcat(path, "/", sizeof(path)); |
| @@ -152,26 +156,41 @@ tinyrad_conf( | |||
| 152 | tinyrad_conf_file(tr, dict, path); | 156 | tinyrad_conf_file(tr, dict, path); |
| 153 | }; | 157 | }; |
| 154 | 158 | ||
| 155 | // lookup user | 159 | // process "~/.{$TINYRADRC}" |
| 156 | getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); | 160 | tinyrad_strlcpy(path, home, sizeof(path)); |
| 157 | prefix = (((pwres)) ? pwres->pw_dir : "/"); | ||
| 158 | |||
| 159 | // search for hidden RC file in home directory | ||
| 160 | tinyrad_strlcpy(path, prefix, sizeof(path)); | ||
| 161 | tinyrad_strlcat(path, "/.", sizeof(path)); | 161 | tinyrad_strlcat(path, "/.", sizeof(path)); |
| 162 | tinyrad_strlcat(path, suffix, sizeof(path)); | 162 | tinyrad_strlcat(path, suffix, sizeof(path)); |
| 163 | tinyrad_conf_file(tr, dict, path); | 163 | tinyrad_conf_file(tr, dict, path); |
| 164 | 164 | ||
| 165 | // search for RC file in home directory | 165 | // process "~/${TINYRADRC}" |
| 166 | tinyrad_strlcpy(path, prefix, sizeof(path)); | 166 | tinyrad_strlcpy(path, home, sizeof(path)); |
| 167 | tinyrad_strlcat(path, "/", sizeof(path)); | 167 | tinyrad_strlcat(path, "/", sizeof(path)); |
| 168 | tinyrad_strlcat(path, suffix, sizeof(path)); | 168 | tinyrad_strlcat(path, suffix, sizeof(path)); |
| 169 | tinyrad_conf_file(tr, dict, path); | 169 | tinyrad_conf_file(tr, dict, path); |
| 170 | 170 | ||
| 171 | // load global configuration | 171 | // process "${TINYRADCONF}" |
| 172 | if ((filename = getenv("TINYRADCONF")) == NULL) | 172 | if ((filename = getenv("TINYRADCONF"))) |
| 173 | filename = SYSCONFDIR "/tinyrad.conf"; | 173 | tinyrad_conf_file(tr, dict, filename); |
| 174 | tinyrad_conf_file(tr, dict, filename); | 174 | |
| 175 | // process "./tinyradrc" | ||
| 176 | if ((getcwd(path, sizeof(path)))) | ||
| 177 | { | ||
| 178 | tinyrad_strlcat(path, "/tinyradrc", sizeof(path)); | ||
| 179 | tinyrad_conf_file(tr, dict, path); | ||
| 180 | }; | ||
| 181 | |||
| 182 | // process "~/.tinyradrc" | ||
| 183 | tinyrad_strlcpy(path, home, sizeof(path)); | ||
| 184 | tinyrad_strlcat(path, "/.tinyradrc", sizeof(path)); | ||
| 185 | tinyrad_conf_file(tr, dict, path); | ||
| 186 | |||
| 187 | // process "~/tinyradrc" | ||
| 188 | tinyrad_strlcpy(path, home, sizeof(path)); | ||
| 189 | tinyrad_strlcat(path, "/tinyradrc", sizeof(path)); | ||
| 190 | tinyrad_conf_file(tr, dict, path); | ||
| 191 | |||
| 192 | // process "/usr/local/etc/tinyrad.conf" | ||
| 193 | tinyrad_conf_file(tr, dict, SYSCONFDIR "/tinyrad.conf"); | ||
| 175 | 194 | ||
| 176 | return(TRAD_SUCCESS); | 195 | return(TRAD_SUCCESS); |
| 177 | } | 196 | } |
