Changeset 1354:0dff6a604b0a in freeDiameter for extensions/acl_wl/acl_wl.c
- Timestamp:
- May 17, 2019, 7:59:19 PM (5 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/acl_wl/acl_wl.c
r741 r1354 38 38 */ 39 39 40 #include <pthread.h> 41 #include <signal.h> 42 40 43 #include "acl_wl.h" 44 45 static pthread_rwlock_t acl_wl_lock; 46 47 #define MODULE_NAME "acl_wl" 48 49 static char *acl_wl_config_file; 41 50 42 51 /* The validator function */ … … 54 63 /* Default to unknown result */ 55 64 *auth = 0; 56 65 66 if (pthread_rwlock_rdlock(&acl_wl_lock) != 0) { 67 fd_log_notice("%s: read-lock failed, skipping handler", MODULE_NAME); 68 return 0; 69 } 70 57 71 /* Now search the peer in our tree */ 58 72 CHECK_FCT( aw_tree_lookup(info->pi_diamid, &res) ); 73 74 if (pthread_rwlock_unlock(&acl_wl_lock) != 0) { 75 fd_log_notice("%s: read-unlock failed after aw_tree_lookup, exiting", MODULE_NAME); 76 exit(1); 77 } 78 59 79 if (res < 0) { 60 80 /* The peer is not whitelisted */ … … 88 108 } 89 109 110 static volatile int in_signal_handler = 0; 111 112 /* signal handler */ 113 static void sig_hdlr(void) 114 { 115 struct fd_list old_tree; 116 117 if (in_signal_handler) { 118 fd_log_error("%s: already handling a signal, ignoring new one", MODULE_NAME); 119 return; 120 } 121 in_signal_handler = 1; 122 123 if (pthread_rwlock_wrlock(&acl_wl_lock) != 0) { 124 fd_log_error("%s: locking failed, aborting config reload", MODULE_NAME); 125 return; 126 } 127 128 /* save old config in case reload goes wrong */ 129 old_tree = tree_root; 130 fd_list_init(&tree_root, NULL); 131 132 if (aw_conf_handle(acl_wl_config_file) != 0) { 133 fd_log_error("%s: error reloading configuration, restoring previous configuration", MODULE_NAME); 134 aw_tree_destroy(); 135 tree_root = old_tree; 136 } else { 137 struct fd_list new_tree; 138 new_tree = tree_root; 139 tree_root = old_tree; 140 aw_tree_destroy(); 141 tree_root = new_tree; 142 } 143 144 if (pthread_rwlock_unlock(&acl_wl_lock) != 0) { 145 fd_log_error("%s: unlocking failed after config reload, exiting", MODULE_NAME); 146 exit(1); 147 } 148 149 fd_log_notice("%s: reloaded configuration", MODULE_NAME); 150 151 in_signal_handler = 0; 152 } 153 154 90 155 /* entry point */ 91 156 static int aw_entry(char * conffile) … … 93 158 TRACE_ENTRY("%p", conffile); 94 159 CHECK_PARAMS(conffile); 95 160 161 acl_wl_config_file = conffile; 162 163 pthread_rwlock_init(&acl_wl_lock, NULL); 164 165 if (pthread_rwlock_wrlock(&acl_wl_lock) != 0) { 166 fd_log_notice("%s: write-lock failed, aborting", MODULE_NAME); 167 return EDEADLK; 168 } 169 96 170 /* Parse configuration file */ 97 171 CHECK_FCT( aw_conf_handle(conffile) ); 98 172 99 173 TRACE_DEBUG(INFO, "Extension ACL_wl initialized with configuration: '%s'", conffile); 100 174 if (TRACE_BOOL(ANNOYING)) { 101 175 aw_tree_dump(); 102 176 } 103 177 178 if (pthread_rwlock_unlock(&acl_wl_lock) != 0) { 179 fd_log_notice("%s: write-unlock failed, aborting", MODULE_NAME); 180 return EDEADLK; 181 } 182 183 /* Register reload callback */ 184 CHECK_FCT(fd_event_trig_regcb(SIGUSR1, MODULE_NAME, sig_hdlr)); 185 104 186 /* Register the validator function */ 105 187 CHECK_FCT( fd_peer_validate_register ( aw_validate ) ); … … 115 197 } 116 198 117 EXTENSION_ENTRY( "acl_wl", aw_entry);199 EXTENSION_ENTRY(MODULE_NAME, aw_entry);
Note: See TracChangeset
for help on using the changeset viewer.