aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-05-31 16:27:59 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-05-31 16:27:59 -0800
commit3995bcbc64353538fa056c7d552efd771fe0c7f1 (patch)
tree50f9930ded8e2f1a796062538f42d2f68a2044ed /lib
parent502082565ba0f5bef320ee243b8a1e82093f2ea1 (diff)
downloadtinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.tar.gz
tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.tar.bz2
tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.tar.xz
tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.zip
libtinytac: adding tinytac_defaults()
Diffstat (limited to 'lib')
-rw-r--r--lib/libtinytac/lconf.c5
-rw-r--r--lib/libtinytac/lmemory.c57
-rw-r--r--lib/libtinytac/lmemory.h10
3 files changed, 61 insertions, 11 deletions
diff --git a/lib/libtinytac/lconf.c b/lib/libtinytac/lconf.c
index e3aa339..4558b73 100644
--- a/lib/libtinytac/lconf.c
+++ b/lib/libtinytac/lconf.c
@@ -150,6 +150,7 @@ int
150tinytac_conf( 150tinytac_conf(
151 unsigned opts ) 151 unsigned opts )
152{ 152{
153 int rc;
153 const char * tintacrc; 154 const char * tintacrc;
154 const char * tinytacconf; 155 const char * tinytacconf;
155 char buff[4096]; 156 char buff[4096];
@@ -174,6 +175,10 @@ tinytac_conf(
174 getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); 175 getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres);
175 home = (((pwres)) ? pwres->pw_dir : "/"); 176 home = (((pwres)) ? pwres->pw_dir : "/");
176 177
178 // load defaults
179 if ((rc = tinytac_defaults(NULL)) != TTAC_SUCCESS)
180 return(rc);
181
177 // process "/usr/local/etc/tinytac.conf" 182 // process "/usr/local/etc/tinytac.conf"
178 tinytac_conf_file(SYSCONFDIR "/tinytac.conf"); 183 tinytac_conf_file(SYSCONFDIR "/tinytac.conf");
179 184
diff --git a/lib/libtinytac/lmemory.c b/lib/libtinytac/lmemory.c
index 8f35104..4d5a08a 100644
--- a/lib/libtinytac/lmemory.c
+++ b/lib/libtinytac/lmemory.c
@@ -155,6 +155,29 @@ const char * tinytac_dflt_hosts = TTAC_DFLT_HOSTS;
155#pragma mark TinyTac functions 155#pragma mark TinyTac functions
156 156
157int 157int
158tinytac_defaults(
159 TinyTac * tt )
160{
161 int rc;
162
163 if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_ASCII, NULL)) != TTAC_SUCCESS) return(rc);
164 if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_PAP, NULL)) != TTAC_SUCCESS) return(rc);
165 if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_CHAP, NULL)) != TTAC_SUCCESS) return(rc);
166 if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_MSCHAP, NULL)) != TTAC_SUCCESS) return(rc);
167 if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_MSCHAPV2, NULL)) != TTAC_SUCCESS) return(rc);
168 if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, NULL)) != TTAC_SUCCESS) return(rc);
169 if ((rc = tinytac_set_option(tt, TTAC_OPT_IPV4, NULL)) != TTAC_SUCCESS) return(rc);
170 if ((rc = tinytac_set_option(tt, TTAC_OPT_IPV6, NULL)) != TTAC_SUCCESS) return(rc);
171 if ((rc = tinytac_set_option(tt, TTAC_OPT_KEY, NULL)) != TTAC_SUCCESS) return(rc);
172 if ((rc = tinytac_set_option(tt, TTAC_OPT_NETWORK_TIMEOUT, NULL)) != TTAC_SUCCESS) return(rc);
173 if ((rc = tinytac_set_option(tt, TTAC_OPT_RANDOM, NULL)) != TTAC_SUCCESS) return(rc);
174 if ((rc = tinytac_set_option(tt, TTAC_OPT_TIMEOUT, NULL)) != TTAC_SUCCESS) return(rc);
175
176 return(TTAC_SUCCESS);
177}
178
179
180int
158tinytac_get_option( 181tinytac_get_option(
159 TinyTac * tt, 182 TinyTac * tt,
160 int option, 183 int option,
@@ -168,8 +191,9 @@ tinytac_get_option(
168 191
169 assert(outvalue != NULL); 192 assert(outvalue != NULL);
170 193
171 if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) 194 if (option != TTAC_OPT_NOINIT)
172 return(rc); 195 if ((rc = tinytac_conf(((tt)) ? tt->opts : 0)) != TTAC_SUCCESS)
196 return(rc);
173 197
174 // get global options 198 // get global options
175 switch(option) 199 switch(option)
@@ -271,19 +295,29 @@ tinytac_initialize(
271 295
272 assert(ttp != NULL); 296 assert(ttp != NULL);
273 297
274 if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) 298 if ((rc = tinytac_conf(opts)) != TTAC_SUCCESS)
275 return(rc); 299 return(rc);
276 300
277 if ((tt = tinytac_obj_alloc(sizeof(TinyTac), (void(*)(void*))&tinytac_tinytac_free)) == NULL) 301 if ((tt = tinytac_obj_alloc(sizeof(TinyTac), (void(*)(void*))&tinytac_tinytac_free)) == NULL)
278 return(TTAC_ENOMEM); 302 return(TTAC_ENOMEM);
279 303
280 // adjust options 304 // apply default options
281 tt->opts = opts; 305 if ((rc = tinytac_defaults(tt)) != TTAC_SUCCESS)
282 if (!(tt->opts & TTAC_IP_UNSPEC)) 306 {
283 tt->opts |= TTAC_IP_UNSPEC; 307 tinytac_tinytac_free(tt);
284 if (!(tt->opts & TTAC_AUTHEN_TYPES)) 308 return(rc);
285 tt->opts |= TTAC_AUTHEN_TYPES; 309 };
310
311 // clear default options if overriden by user
312 if ((opts & TTAC_IP_UNSPEC))
313 tt->opts &= ~TTAC_IP_UNSPEC;
314 if ((opts & TTAC_AUTHEN_TYPES))
315 tt->opts &= ~TTAC_AUTHEN_TYPES;
316 if ((opts & TTAC_RND_METHODS))
317 tt->opts &= ~TTAC_RND_METHODS;
286 318
319 // apply user options
320 tt->opts |= opts;
287 if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, hosts)) != TTAC_SUCCESS) 321 if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, hosts)) != TTAC_SUCCESS)
288 { 322 {
289 tinytac_tinytac_free(tt); 323 tinytac_tinytac_free(tt);
@@ -317,8 +351,9 @@ tinytac_set_option(
317 351
318 assert(invalue != NULL); 352 assert(invalue != NULL);
319 353
320 if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) 354 if (option != TTAC_OPT_NOINIT)
321 return(rc); 355 if ((rc = tinytac_conf(((tt)) ? tt->opts : 0)) != TTAC_SUCCESS)
356 return(rc);
322 357
323 switch(option) 358 switch(option)
324 { 359 {
diff --git a/lib/libtinytac/lmemory.h b/lib/libtinytac/lmemory.h
index a908711..1d4934b 100644
--- a/lib/libtinytac/lmemory.h
+++ b/lib/libtinytac/lmemory.h
@@ -73,6 +73,16 @@ extern const char * tinytac_dflt_hosts;
73////////////////// 73//////////////////
74#pragma mark - Prototypes 74#pragma mark - Prototypes
75 75
76//--------------------//
77// TinyTac prototypes //
78//--------------------//
79#pragma mark TinyTac prototypes
80
81int
82tinytac_defaults(
83 TinyTac * tt );
84
85
76//-------------------// 86//-------------------//
77// object prototypes // 87// object prototypes //
78//-------------------// 88//-------------------//