comparison svr-session.c @ 1654:cc0fc5131c5c

Rename EPKA -> Plugin
author Matt Johnston <matt@ucc.asn.au>
date Wed, 15 May 2019 21:59:45 +0800
parents 76189c9ffea2
children 7c17995bcdfb
comparison
equal deleted inserted replaced
1653:76189c9ffea2 1654:cc0fc5131c5c
87 m_free(svr_ses.addrstring); 87 m_free(svr_ses.addrstring);
88 m_free(svr_ses.remotehost); 88 m_free(svr_ses.remotehost);
89 m_free(svr_ses.childpids); 89 m_free(svr_ses.childpids);
90 svr_ses.childpidsize = 0; 90 svr_ses.childpidsize = 0;
91 91
92 #if DROPBEAR_EPKA 92 #if DROPBEAR_PLUGIN
93 if (svr_ses.epka_plugin_handle != NULL) { 93 if (svr_ses.plugin_handle != NULL) {
94 if (svr_ses.epka_instance) { 94 if (svr_ses.plugin_instance) {
95 svr_ses.epka_instance->delete_plugin(svr_ses.epka_instance); 95 svr_ses.plugin_instance->delete_plugin(svr_ses.plugin_instance);
96 svr_ses.epka_instance = NULL; 96 svr_ses.plugin_instance = NULL;
97 } 97 }
98 98
99 dlclose(svr_ses.epka_plugin_handle); 99 dlclose(svr_ses.plugin_handle);
100 svr_ses.epka_plugin_handle = NULL; 100 svr_ses.plugin_handle = NULL;
101 } 101 }
102 #endif 102 #endif
103 } 103 }
104 104
105 void svr_session(int sock, int childpipe) { 105 void svr_session(int sock, int childpipe) {
120 svr_ses.addrstring = m_malloc(len); 120 svr_ses.addrstring = m_malloc(len);
121 snprintf(svr_ses.addrstring, len, "%s:%s", host, port); 121 snprintf(svr_ses.addrstring, len, "%s:%s", host, port);
122 m_free(host); 122 m_free(host);
123 m_free(port); 123 m_free(port);
124 124
125 #if DROPBEAR_EPKA 125 #if DROPBEAR_PLUGIN
126 /* Initializes the EPKA Plugin */ 126 /* Initializes the PLUGIN Plugin */
127 svr_ses.epka_plugin_handle = NULL; 127 svr_ses.plugin_handle = NULL;
128 svr_ses.epka_instance = NULL; 128 svr_ses.plugin_instance = NULL;
129 if (svr_opts.pubkey_plugin) { 129 if (svr_opts.pubkey_plugin) {
130 #if DEBUG_TRACE 130 #if DEBUG_TRACE
131 const int verbose = debug_trace; 131 const int verbose = debug_trace;
132 #else 132 #else
133 const int verbose = 0; 133 const int verbose = 0;
134 #endif 134 #endif
135 PubkeyExtPlugin_newFn pluginConstructor; 135 PubkeyExtPlugin_newFn pluginConstructor;
136 136
137 /* RTLD_NOW: fails if not all the symbols are resolved now. Better fail now than at run-time */ 137 /* RTLD_NOW: fails if not all the symbols are resolved now. Better fail now than at run-time */
138 svr_ses.epka_plugin_handle = dlopen(svr_opts.pubkey_plugin, RTLD_NOW); 138 svr_ses.plugin_handle = dlopen(svr_opts.pubkey_plugin, RTLD_NOW);
139 if (svr_ses.epka_plugin_handle == NULL) { 139 if (svr_ses.plugin_handle == NULL) {
140 dropbear_exit("failed to load external pubkey plugin '%s': %s", svr_opts.pubkey_plugin, dlerror()); 140 dropbear_exit("failed to load external pubkey plugin '%s': %s", svr_opts.pubkey_plugin, dlerror());
141 } 141 }
142 pluginConstructor = (PubkeyExtPlugin_newFn)dlsym(svr_ses.epka_plugin_handle, DROPBEAR_PUBKEY_PLUGIN_FNNAME_NEW); 142 pluginConstructor = (PubkeyExtPlugin_newFn)dlsym(svr_ses.plugin_handle, DROPBEAR_PUBKEY_PLUGIN_FNNAME_NEW);
143 if (!pluginConstructor) { 143 if (!pluginConstructor) {
144 dropbear_exit("plugin constructor method not found in external pubkey plugin"); 144 dropbear_exit("plugin constructor method not found in external pubkey plugin");
145 } 145 }
146 146
147 /* Create an instance of the plugin */ 147 /* Create an instance of the plugin */
148 svr_ses.epka_instance = pluginConstructor(verbose, svr_opts.pubkey_plugin_options, svr_ses.addrstring); 148 svr_ses.plugin_instance = pluginConstructor(verbose, svr_opts.pubkey_plugin_options, svr_ses.addrstring);
149 if (svr_ses.epka_instance == NULL) { 149 if (svr_ses.plugin_instance == NULL) {
150 dropbear_exit("external plugin initialization failed"); 150 dropbear_exit("external plugin initialization failed");
151 } 151 }
152 /* Check if the plugin is compatible */ 152 /* Check if the plugin is compatible */
153 if ( (svr_ses.epka_instance->api_version[0] != DROPBEAR_EPKA_VERSION_MAJOR) || 153 if ( (svr_ses.plugin_instance->api_version[0] != DROPBEAR_PLUGIN_VERSION_MAJOR) ||
154 (svr_ses.epka_instance->api_version[1] < DROPBEAR_EPKA_VERSION_MINOR) ) { 154 (svr_ses.plugin_instance->api_version[1] < DROPBEAR_PLUGIN_VERSION_MINOR) ) {
155 dropbear_exit("plugin version check failed: " 155 dropbear_exit("plugin version check failed: "
156 "Dropbear=%d.%d, plugin=%d.%d", 156 "Dropbear=%d.%d, plugin=%d.%d",
157 DROPBEAR_EPKA_VERSION_MAJOR, DROPBEAR_EPKA_VERSION_MINOR, 157 DROPBEAR_PLUGIN_VERSION_MAJOR, DROPBEAR_PLUGIN_VERSION_MINOR,
158 svr_ses.epka_instance->api_version[0], svr_ses.epka_instance->api_version[1]); 158 svr_ses.plugin_instance->api_version[0], svr_ses.plugin_instance->api_version[1]);
159 } 159 }
160 if (svr_ses.epka_instance->api_version[1] > DROPBEAR_EPKA_VERSION_MINOR) { 160 if (svr_ses.plugin_instance->api_version[1] > DROPBEAR_PLUGIN_VERSION_MINOR) {
161 dropbear_log(LOG_WARNING, "plugin API newer than dropbear API: " 161 dropbear_log(LOG_WARNING, "plugin API newer than dropbear API: "
162 "Dropbear=%d.%d, plugin=%d.%d", 162 "Dropbear=%d.%d, plugin=%d.%d",
163 DROPBEAR_EPKA_VERSION_MAJOR, DROPBEAR_EPKA_VERSION_MINOR, 163 DROPBEAR_PLUGIN_VERSION_MAJOR, DROPBEAR_PLUGIN_VERSION_MINOR,
164 svr_ses.epka_instance->api_version[0], svr_ses.epka_instance->api_version[1]); 164 svr_ses.plugin_instance->api_version[0], svr_ses.plugin_instance->api_version[1]);
165 } 165 }
166 dropbear_log(LOG_INFO, "successfully loaded and initialized pubkey plugin '%s'", svr_opts.pubkey_plugin); 166 dropbear_log(LOG_INFO, "successfully loaded and initialized pubkey plugin '%s'", svr_opts.pubkey_plugin);
167 } 167 }
168 #endif 168 #endif
169 169
207 void svr_dropbear_exit(int exitcode, const char* format, va_list param) { 207 void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
208 char exitmsg[150]; 208 char exitmsg[150];
209 char fullmsg[300]; 209 char fullmsg[300];
210 int i; 210 int i;
211 211
212 #if DROPBEAR_EPKA 212 #if DROPBEAR_PLUGIN
213 if ((ses.epka_session != NULL)) { 213 if ((ses.plugin_session != NULL)) {
214 svr_ses.epka_instance->delete_session(ses.epka_session); 214 svr_ses.plugin_instance->delete_session(ses.plugin_session);
215 } 215 }
216 ses.epka_session = NULL; 216 ses.plugin_session = NULL;
217 #endif 217 #endif
218 218
219 /* Render the formatted exit message */ 219 /* Render the formatted exit message */
220 vsnprintf(exitmsg, sizeof(exitmsg), format, param); 220 vsnprintf(exitmsg, sizeof(exitmsg), format, param);
221 221