1 /* $NetBSD: postconf_misc.c,v 1.3 2023/12/23 20:30:44 christos Exp $ */ 2 3 /*++ 4 /* NAME 5 /* postconf_misc 3 6 /* SUMMARY 7 /* miscellaneous low-level code 8 /* SYNOPSIS 9 /* #include <postconf.h> 10 /* 11 /* void pcf_set_config_dir() 12 /* 13 /* const char *pcf_get_main_path() 14 /* 15 /* const char *pcf_get_master_path() 16 /* DESCRIPTION 17 /* pcf_set_config_dir() forcibly overrides the var_config_dir 18 /* parameter setting with the value from the environment or 19 /* with the default pathname, and updates the mail parameter 20 /* dictionary. 21 /* 22 /* pcf_get_main_path() and pcf_get_master_path() return a 23 /* pointer to a cached main.cf or master.cf full pathname, 24 /* based on the current var_config_dir setting. The functions 25 /* call pcf_set_config_dir() when no full pathname is cached. 26 /* DIAGNOSTICS 27 /* Problems are reported to the standard error stream. 28 /* LICENSE 29 /* .ad 30 /* .fi 31 /* The Secure Mailer license must be distributed with this software. 32 /* AUTHOR(S) 33 /* Wietse Venema 34 /* IBM T.J. Watson Research 35 /* P.O. Box 704 36 /* Yorktown Heights, NY 10598, USA 37 /*--*/ 38 39 /* System library. */ 40 41 #include <sys_defs.h> 42 43 /* Utility library. */ 44 45 #include <mymalloc.h> 46 #include <safe.h> 47 #include <stringops.h> 48 49 /* Global library. */ 50 51 #include <mail_params.h> 52 #include <mail_conf.h> 53 54 /* Application-specific. */ 55 56 #include <postconf.h> 57 58 /* 59 * Pathname cache, based on current var_config_dir. 60 */ 61 static char *pcf_main_path = 0; 62 static char *pcf_master_path = 0; 63 64 /* pcf_set_config_dir - forcibly override var_config_dir */ 65 66 void pcf_set_config_dir(void) 67 { 68 char *config_dir; 69 70 if (var_config_dir) 71 myfree(var_config_dir); 72 if ((config_dir = safe_getenv(CONF_ENV_PATH)) != 0) { 73 var_config_dir = mystrdup(config_dir); 74 set_mail_conf_str(VAR_CONFIG_DIR, var_config_dir); 75 } else { 76 var_config_dir = mystrdup(DEF_CONFIG_DIR); 77 } 78 79 /* 80 * Populate the full pathname cache. 81 */ 82 if (pcf_main_path) 83 myfree(pcf_main_path); 84 pcf_main_path = 85 concatenate(var_config_dir, "/", MAIN_CONF_FILE, (char *) 0); 86 if (pcf_master_path) 87 myfree(pcf_master_path); 88 pcf_master_path = 89 concatenate(var_config_dir, "/", MASTER_CONF_FILE, (char *) 0); 90 } 91 92 /* pcf_get_main_path - generate and return full main.cf pathname */ 93 94 const char *pcf_get_main_path(void) 95 { 96 if (pcf_main_path == 0) 97 pcf_set_config_dir(); 98 return (pcf_main_path); 99 } 100 101 /* pcf_get_master_path - generate and return full master.cf pathname */ 102 103 const char *pcf_get_master_path(void) 104 { 105 if (pcf_master_path == 0) 106 pcf_set_config_dir(); 107 return (pcf_master_path); 108 } 109