blob: ceff5073a4f5aba806b9b74d36297f3968d8c566 [file] [log] [blame]
Radek Krejci469aab82012-07-22 18:42:20 +02001/*!
2 * \file mod_netconf.c
3 * \brief NETCONF Apache modul for Netopeer
4 * \author Tomas Cejka <cejkat@cesnet.cz>
5 * \author Radek Krejci <rkrejci@cesnet.cz>
6 * \date 2011
7 * \date 2012
8 */
9/*
10 * Copyright (C) 2011-2012 CESNET
11 *
12 * LICENSE TERMS
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
23 * 3. Neither the name of the Company nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
26 *
27 * ALTERNATIVELY, provided that this notice is retained in full, this
28 * product may be distributed under the terms of the GNU General Public
29 * License (GPL) version 2 or later, in which case the provisions
30 * of the GPL apply INSTEAD OF those given above.
31 *
32 * This software is provided ``as is'', and any express or implied
33 * warranties, including, but not limited to, the implied warranties of
34 * merchantability and fitness for a particular purpose are disclaimed.
35 * In no event shall the company or contributors be liable for any
36 * direct, indirect, incidental, special, exemplary, or consequential
37 * damages (including, but not limited to, procurement of substitute
38 * goods or services; loss of use, data, or profits; or business
39 * interruption) however caused and on any theory of liability, whether
40 * in contract, strict liability, or tort (including negligence or
41 * otherwise) arising in any way out of the use of this software, even
42 * if advised of the possibility of such damage.
43 *
44 */
45
Radek Krejci7b4ddd02012-07-30 08:09:58 +020046#include <unistd.h>
47#include <poll.h>
Radek Krejci469aab82012-07-22 18:42:20 +020048#include <sys/types.h>
49#include <sys/socket.h>
50#include <sys/un.h>
David Kupka8e60a372012-09-04 09:15:20 +020051#include <pthread.h>
52#include <ctype.h>
Radek Krejci7b4ddd02012-07-30 08:09:58 +020053
54#include <unixd.h>
55#include <httpd.h>
56#include <http_log.h>
57#include <http_config.h>
58
59#include <apr_sha1.h>
60#include <apr_hash.h>
61#include <apr_signal.h>
62#include <apr_strings.h>
Radek Krejci469aab82012-07-22 18:42:20 +020063
Radek Krejci8fd1f5e2012-07-24 17:33:36 +020064#include <json/json.h>
65
Radek Krejci469aab82012-07-22 18:42:20 +020066#include <libnetconf.h>
Radek Krejci7b4ddd02012-07-30 08:09:58 +020067
Radek Krejci469aab82012-07-22 18:42:20 +020068
69#define MAX_PROCS 5
Radek Krejci6cb08982012-07-25 18:01:06 +020070#define SOCKET_FILENAME "/tmp/mod_netconf.sock"
Radek Krejci469aab82012-07-22 18:42:20 +020071#define MAX_SOCKET_CL 10
72#define BUFFER_SIZE 4096
73
74/* sleep in master process for non-blocking socket reading */
75#define SLEEP_TIME 200
76
77#ifndef offsetof
78#define offsetof(type, member) ((size_t) ((type *) 0)->member)
79#endif
80
81struct timeval timeout = { 1, 0 };
82
Radek Krejci8fd1f5e2012-07-24 17:33:36 +020083typedef enum MSG_TYPE {
84 REPLY_OK,
85 REPLY_DATA,
86 REPLY_ERROR,
Radek Krejci9e04c7b2012-07-26 15:54:25 +020087 REPLY_INFO,
Radek Krejci8fd1f5e2012-07-24 17:33:36 +020088 MSG_CONNECT,
89 MSG_DISCONNECT,
90 MSG_GET,
91 MSG_GETCONFIG,
92 MSG_EDITCONFIG,
93 MSG_COPYCONFIG,
94 MSG_DELETECONFIG,
95 MSG_LOCK,
96 MSG_UNLOCK,
Radek Krejci9e04c7b2012-07-26 15:54:25 +020097 MSG_KILL,
Radek Krejci80c10d92012-07-30 08:38:50 +020098 MSG_INFO,
99 MSG_GENERIC
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200100} MSG_TYPE;
101
Radek Krejci469aab82012-07-22 18:42:20 +0200102#define MSG_OK 0
103#define MSG_OPEN 1
104#define MSG_DATA 2
105#define MSG_CLOSE 3
106#define MSG_ERROR 4
107#define MSG_UNKNOWN 5
108
Radek Krejci469aab82012-07-22 18:42:20 +0200109module AP_MODULE_DECLARE_DATA netconf_module;
110
111typedef struct {
Radek Krejci469aab82012-07-22 18:42:20 +0200112 apr_pool_t *pool;
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200113 apr_proc_t *forkproc;
114 char* sockname;
Radek Krejcif23850c2012-07-23 16:14:17 +0200115} mod_netconf_cfg;
Radek Krejci469aab82012-07-22 18:42:20 +0200116
David Kupka8e60a372012-09-04 09:15:20 +0200117struct pass_to_thread {
118 int client; /**< opened socket */
119 apr_pool_t * pool; /**< ?? */
120 server_rec * server; /**< ?? */
121 apr_hash_t * netconf_sessions_list; /**< ?? */
122};
123
124struct session_with_mutex {
125 struct nc_session * session; /**< netconf session */
126 pthread_mutex_t lock; /**< mutex protecting the session from multiple access */
127};
128
129pthread_rwlock_t session_lock; /**< mutex protecting netconf_session_list from multiple access errors */
130
Radek Krejci469aab82012-07-22 18:42:20 +0200131volatile int isterminated = 0;
132
133static char* password;
134
135
136static void signal_handler(int sign)
137{
138 switch (sign) {
139 case SIGTERM:
140 isterminated = 1;
Radek Krejci469aab82012-07-22 18:42:20 +0200141 break;
142 }
143}
144
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200145static char* gen_ncsession_hash( const char* hostname, const char* port, const char* sid)
Radek Krejci469aab82012-07-22 18:42:20 +0200146{
Radek Krejcif23850c2012-07-23 16:14:17 +0200147 unsigned char hash_raw[APR_SHA1_DIGESTSIZE];
148 int i;
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200149 char* hash;
Radek Krejcif23850c2012-07-23 16:14:17 +0200150
Radek Krejci469aab82012-07-22 18:42:20 +0200151 apr_sha1_ctx_t sha1_ctx;
152 apr_sha1_init(&sha1_ctx);
153 apr_sha1_update(&sha1_ctx, hostname, strlen(hostname));
154 apr_sha1_update(&sha1_ctx, port, strlen(port));
155 apr_sha1_update(&sha1_ctx, sid, strlen(sid));
Radek Krejcif23850c2012-07-23 16:14:17 +0200156 apr_sha1_final(hash_raw, &sha1_ctx);
Radek Krejci469aab82012-07-22 18:42:20 +0200157
Radek Krejcif23850c2012-07-23 16:14:17 +0200158 /* convert binary hash into hex string, which is printable */
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200159 hash = malloc(sizeof(char) * ((2*APR_SHA1_DIGESTSIZE)+1));
Radek Krejcif23850c2012-07-23 16:14:17 +0200160 for (i = 0; i < APR_SHA1_DIGESTSIZE; i++) {
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200161 snprintf(hash + (2*i), 3, "%02x", hash_raw[i]);
Radek Krejcif23850c2012-07-23 16:14:17 +0200162 }
163 //hash[2*APR_SHA1_DIGESTSIZE] = 0;
Radek Krejci469aab82012-07-22 18:42:20 +0200164
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200165 return (hash);
Radek Krejci469aab82012-07-22 18:42:20 +0200166}
167
168int netconf_callback_ssh_hostkey_check (const char* hostname, int keytype, const char* fingerprint)
169{
170 /* always approve */
171 return (EXIT_SUCCESS);
172}
173
174char* netconf_callback_sshauth_password (const char* username, const char* hostname)
175{
176 char* buf;
177
178 buf = malloc ((strlen(password) + 1) * sizeof(char));
179 apr_cpystrn(buf, password, strlen(password) + 1);
180
181 return (buf);
182}
183
184void netconf_callback_sshauth_interactive (const char* name,
185 int name_len,
186 const char* instruction,
187 int instruction_len,
188 int num_prompts,
189 const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts,
190 LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses,
191 void** abstract)
192{
193 int i;
194
195 for (i=0; i<num_prompts; i++) {
196 responses[i].text = malloc ((strlen(password) + 1) * sizeof(char));
197 apr_cpystrn(responses[i].text, password, strlen(password) + 1);
198 responses[i].length = strlen(responses[i].text) + 1;
199 }
200
201 return;
202}
203
Radek Krejcic11fd862012-07-26 12:41:21 +0200204static json_object *err_reply = NULL;
205void netconf_callback_error_process(const char* tag,
206 const char* type,
207 const char* severity,
208 const char* apptag,
209 const char* path,
210 const char* message,
211 const char* attribute,
212 const char* element,
213 const char* ns,
214 const char* sid)
215{
216 err_reply = json_object_new_object();
217 json_object_object_add(err_reply, "type", json_object_new_int(REPLY_ERROR));
218 if (tag) json_object_object_add(err_reply, "error-tag", json_object_new_string(tag));
219 if (type) json_object_object_add(err_reply, "error-type", json_object_new_string(type));
220 if (severity) json_object_object_add(err_reply, "error-severity", json_object_new_string(severity));
221 if (apptag) json_object_object_add(err_reply, "error-app-tag", json_object_new_string(apptag));
222 if (path) json_object_object_add(err_reply, "error-path", json_object_new_string(path));
223 if (message) json_object_object_add(err_reply, "error-message", json_object_new_string(message));
224 if (attribute) json_object_object_add(err_reply, "bad-attribute", json_object_new_string(attribute));
225 if (element) json_object_object_add(err_reply, "bad-element", json_object_new_string(element));
226 if (ns) json_object_object_add(err_reply, "bad-namespace", json_object_new_string(ns));
227 if (sid) json_object_object_add(err_reply, "session-id", json_object_new_string(sid));
228}
229
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200230static char* netconf_connect(server_rec* server, apr_pool_t* pool, apr_hash_t* conns, const char* host, const char* port, const char* user, const char* pass)
Radek Krejci469aab82012-07-22 18:42:20 +0200231{
Radek Krejci469aab82012-07-22 18:42:20 +0200232 struct nc_session* session;
David Kupka8e60a372012-09-04 09:15:20 +0200233 struct session_with_mutex * locked_session;
Radek Krejcif23850c2012-07-23 16:14:17 +0200234 char *session_key;
David Kupka8e60a372012-09-04 09:15:20 +0200235 struct nc_cpblts * cpblts = nc_session_get_cpblts_default ();
236
237 nc_cpblts_add(cpblts, "urn:cesnet:tmc:netopeer:1.0");
Radek Krejci469aab82012-07-22 18:42:20 +0200238
239 /* connect to the requested NETCONF server */
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200240 password = (char*)pass;
David Kupka8e60a372012-09-04 09:15:20 +0200241 session = nc_session_connect(host, (unsigned short) atoi (port), user, cpblts);
242
243 nc_cpblts_free (cpblts);
Radek Krejci469aab82012-07-22 18:42:20 +0200244
245 /* if connected successful, add session to the list */
246 if (session != NULL) {
247 /* generate hash for the session */
Radek Krejcic11fd862012-07-26 12:41:21 +0200248 session_key = gen_ncsession_hash(
249 (host==NULL) ? "localhost" : host,
250 (port==NULL) ? "830" : port,
Radek Krejcia282bed2012-07-27 14:43:45 +0200251 nc_session_get_id(session));
David Kupka8e60a372012-09-04 09:15:20 +0200252
253 if ((locked_session = malloc (sizeof (struct session_with_mutex))) == NULL || pthread_mutex_init (&locked_session->lock, NULL) != 0) {
254 nc_session_free(session);
255 free (locked_session);
256 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Creating structure session_with_mutex failed %d (%s)", errno, strerror(errno));
257 return NULL;
258 }
259 locked_session->session = session;
260 pthread_mutex_init (&locked_session->lock, NULL);
261 /* get exclusive access to sessions_list (conns) */
262 if (pthread_rwlock_wrlock (&session_lock) != 0) {
263 nc_session_free(session);
264 free (locked_session);
265 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while locking rwlock: %d (%s)", errno, strerror(errno));
266 return NULL;
267 }
268 apr_hash_set(conns, apr_pstrdup(pool, session_key), APR_HASH_KEY_STRING, (void *) locked_session);
269 /* end of critical section */
270 if (pthread_rwlock_unlock (&session_lock) != 0) {
271 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
272 return NULL;
273 }
Radek Krejci469aab82012-07-22 18:42:20 +0200274 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, server, "NETCONF session established");
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200275 return (session_key);
Radek Krejci469aab82012-07-22 18:42:20 +0200276 } else {
277 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Connection could not be established");
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200278 return (NULL);
Radek Krejci469aab82012-07-22 18:42:20 +0200279 }
280
Radek Krejci469aab82012-07-22 18:42:20 +0200281}
282
Radek Krejci80c10d92012-07-30 08:38:50 +0200283static int netconf_close(server_rec* server, apr_hash_t* conns, const char* session_key)
Radek Krejci469aab82012-07-22 18:42:20 +0200284{
285 struct nc_session *ns = NULL;
David Kupka8e60a372012-09-04 09:15:20 +0200286 struct session_with_mutex * locked_session;
Radek Krejci469aab82012-07-22 18:42:20 +0200287
Radek Krejcif23850c2012-07-23 16:14:17 +0200288 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Key in hash to get: %s", session_key);
David Kupka8e60a372012-09-04 09:15:20 +0200289 /* get exclusive (write) access to sessions_list (conns) */
290 if (pthread_rwlock_wrlock (&session_lock) != 0) {
291 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while locking rwlock: %d (%s)", errno, strerror(errno));
292 return EXIT_FAILURE;
293 }
294 locked_session = (struct session_with_mutex *)apr_hash_get(conns, session_key, APR_HASH_KEY_STRING);
295 if (locked_session != NULL) {
296 pthread_mutex_destroy(&locked_session->lock);
297 ns = locked_session->session;
298 free (locked_session);
299 }
Radek Krejci469aab82012-07-22 18:42:20 +0200300 if (ns != NULL) {
301 nc_session_close (ns, "NETCONF session closed by client");
302 nc_session_free (ns);
303 ns = NULL;
304
305 /* remove session from the active sessions list */
306 apr_hash_set(conns, session_key, APR_HASH_KEY_STRING, NULL);
David Kupka8e60a372012-09-04 09:15:20 +0200307 /* end of critical section */
308 if (pthread_rwlock_unlock (&session_lock) != 0) {
309 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
310 return EXIT_FAILURE;
311 }
Radek Krejci469aab82012-07-22 18:42:20 +0200312 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, server, "NETCONF session closed");
Radek Krejcif23850c2012-07-23 16:14:17 +0200313
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200314 return (EXIT_SUCCESS);
Radek Krejci469aab82012-07-22 18:42:20 +0200315 } else {
316 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Unknown session to close");
Radek Krejci8fd1f5e2012-07-24 17:33:36 +0200317 return (EXIT_FAILURE);
Radek Krejci469aab82012-07-22 18:42:20 +0200318 }
319}
320
Radek Krejci80c10d92012-07-30 08:38:50 +0200321static int netconf_op(server_rec* server, apr_hash_t* conns, const char* session_key, nc_rpc* rpc)
Radek Krejci469aab82012-07-22 18:42:20 +0200322{
323 struct nc_session *session = NULL;
David Kupka8e60a372012-09-04 09:15:20 +0200324 struct session_with_mutex * locked_session;
Radek Krejci035bf4e2012-07-25 10:59:09 +0200325 nc_reply* reply;
326 int retval = EXIT_SUCCESS;
327
Radek Krejci8e4632a2012-07-26 13:40:34 +0200328 /* check requests */
329 if (rpc == NULL) {
330 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: rpc is not created");
331 return (EXIT_FAILURE);
332 }
333
David Kupka8e60a372012-09-04 09:15:20 +0200334 /* get non-exclusive (read) access to sessions_list (conns) */
335 if (pthread_rwlock_rdlock (&session_lock) != 0) {
336 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while locking rwlock: %d (%s)", errno, strerror(errno));
337 return EXIT_FAILURE;
338 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200339 /* get session where send the RPC */
David Kupka8e60a372012-09-04 09:15:20 +0200340 locked_session = (struct session_with_mutex *)apr_hash_get(conns, session_key, APR_HASH_KEY_STRING);
341 if (locked_session != NULL) {
342 session = locked_session->session;
343 }
Radek Krejci035bf4e2012-07-25 10:59:09 +0200344 if (session != NULL) {
David Kupka8e60a372012-09-04 09:15:20 +0200345 /* get exclusive access to session */
346 if (pthread_mutex_lock(&locked_session->lock) != 0) {
347 /* unlock before returning error */
348 if (pthread_rwlock_unlock (&session_lock) != 0) {
349 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while locking rwlock: %d (%s)", errno, strerror(errno));
350 return EXIT_FAILURE;
351 }
352 return EXIT_FAILURE;
353 }
Radek Krejci035bf4e2012-07-25 10:59:09 +0200354 /* send the request and get the reply */
355 nc_session_send_rpc (session, rpc);
Radek Krejci035bf4e2012-07-25 10:59:09 +0200356 if (nc_session_recv_reply (session, &reply) == 0) {
Radek Krejci035bf4e2012-07-25 10:59:09 +0200357 if (nc_session_get_status(session) != NC_SESSION_STATUS_WORKING) {
Radek Krejci035bf4e2012-07-25 10:59:09 +0200358 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: receiving rpc-reply failed");
David Kupka8e60a372012-09-04 09:15:20 +0200359 /* first release exclusive lock for this session */
360 pthread_mutex_unlock(&locked_session->lock);
361 /* release read lock, netconf_close will get exclusive access and close this session */
362 if (pthread_rwlock_unlock (&session_lock) != 0) {
363 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
364 return EXIT_FAILURE;
365 }
Radek Krejci035bf4e2012-07-25 10:59:09 +0200366 netconf_close(server, conns, session_key);
Radek Krejci035bf4e2012-07-25 10:59:09 +0200367 return (EXIT_FAILURE);
368 }
David Kupka8e60a372012-09-04 09:15:20 +0200369 /* first release exclusive lock for this session */
370 pthread_mutex_unlock(&locked_session->lock);
371 /* unlock before returning error */
372 if (pthread_rwlock_unlock (&session_lock) != 0) {
373 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
374 return EXIT_FAILURE;
375 }
Radek Krejci035bf4e2012-07-25 10:59:09 +0200376 /* there is error handled by callback */
377 return (EXIT_FAILURE);
378 }
David Kupka8e60a372012-09-04 09:15:20 +0200379 /* first release exclusive lock for this session */
380 pthread_mutex_unlock(&locked_session->lock);
381 /* end of critical section */
382 if (pthread_rwlock_unlock (&session_lock) != 0) {
383 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
384 return EXIT_FAILURE;
385 }
Radek Krejci035bf4e2012-07-25 10:59:09 +0200386
387 switch (nc_reply_get_type (reply)) {
388 case NC_REPLY_OK:
389 retval = EXIT_SUCCESS;
390 break;
391 default:
392 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: unexpected rpc-reply");
393 retval = EXIT_FAILURE;
394 break;
395 }
396 nc_reply_free(reply);
397 return (retval);
398 } else {
399 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Unknown session to process.");
400 return (EXIT_FAILURE);
401 }
402}
Radek Krejci80c10d92012-07-30 08:38:50 +0200403
404static char* netconf_opdata(server_rec* server, apr_hash_t* conns, const char* session_key, nc_rpc* rpc)
Radek Krejci8e4632a2012-07-26 13:40:34 +0200405{
406 struct nc_session *session = NULL;
David Kupka8e60a372012-09-04 09:15:20 +0200407 struct session_with_mutex * locked_session;
Radek Krejci8e4632a2012-07-26 13:40:34 +0200408 nc_reply* reply;
409 char* data;
410
411 /* check requests */
412 if (rpc == NULL) {
413 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: rpc is not created");
414 return (NULL);
415 }
416
David Kupka8e60a372012-09-04 09:15:20 +0200417 /* get non-exclusive (read) access to sessions_list (conns) */
418 if (pthread_rwlock_rdlock (&session_lock) != 0) {
419 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while locking rwlock: %d (%s)", errno, strerror(errno));
420 return NULL;
421 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200422 /* get session where send the RPC */
David Kupka8e60a372012-09-04 09:15:20 +0200423 locked_session = (struct session_with_mutex *)apr_hash_get(conns, session_key, APR_HASH_KEY_STRING);
424 if (locked_session != NULL) {
425 session = locked_session->session;
426 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200427 if (session != NULL) {
David Kupka8e60a372012-09-04 09:15:20 +0200428 /* get exclusive access to session */
429 if (pthread_mutex_lock(&locked_session->lock) != 0) {
430 /* unlock before returning error */
431 if (pthread_rwlock_unlock (&session_lock) != 0) {
432 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while locking rwlock: %d (%s)", errno, strerror(errno));
433 return NULL;
434 }
435 return NULL;
436 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200437 /* send the request and get the reply */
438 nc_session_send_rpc (session, rpc);
439 if (nc_session_recv_reply (session, &reply) == 0) {
Radek Krejci8e4632a2012-07-26 13:40:34 +0200440 if (nc_session_get_status(session) != NC_SESSION_STATUS_WORKING) {
441 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: receiving rpc-reply failed");
David Kupka8e60a372012-09-04 09:15:20 +0200442 /* first release exclusive lock for this session */
443 pthread_mutex_unlock(&locked_session->lock);
444 /* release read lock, netconf_close will get exclusive access and close this session */
445 if (pthread_rwlock_unlock (&session_lock) != 0) {
446 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
447 return NULL;
448 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200449 netconf_close(server, conns, session_key);
450 return (NULL);
451 }
David Kupka8e60a372012-09-04 09:15:20 +0200452 /* first release exclusive lock for this session */
453 pthread_mutex_unlock(&locked_session->lock);
454 /* unlock before returning error */
455 if (pthread_rwlock_unlock (&session_lock) != 0) {
456 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
457 return NULL;
458 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200459 /* there is error handled by callback */
460 return (NULL);
461 }
David Kupka8e60a372012-09-04 09:15:20 +0200462 /* first release exclusive lock for this session */
463 pthread_mutex_unlock(&locked_session->lock);
464 /* end of critical section */
465 if (pthread_rwlock_unlock (&session_lock) != 0) {
466 ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "Error while unlocking rwlock: %d (%s)", errno, strerror(errno));
467 return NULL;
468 }
Radek Krejci8e4632a2012-07-26 13:40:34 +0200469
470 switch (nc_reply_get_type (reply)) {
471 case NC_REPLY_DATA:
472 if ((data = nc_reply_get_data (reply)) == NULL) {
473 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: no data from reply");
474 return (NULL);
475 }
476 break;
477 default:
478 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: unexpected rpc-reply");
479 return (NULL);
480 }
481 nc_reply_free(reply);
482
483 return (data);
484 } else {
485 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Unknown session to process.");
486 return (NULL);
487 }
488}
489
Radek Krejci80c10d92012-07-30 08:38:50 +0200490static char* netconf_getconfig(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE source, const char* filter)
Radek Krejci8e4632a2012-07-26 13:40:34 +0200491{
492 nc_rpc* rpc;
493 struct nc_filter *f = NULL;
494 char* data = NULL;
495
496 /* create filter if set */
497 if (filter != NULL) {
498 f = nc_filter_new(NC_FILTER_SUBTREE, filter);
499 }
500
501 /* create requests */
502 rpc = nc_rpc_getconfig (source, f);
503 nc_filter_free(f);
504 if (rpc == NULL) {
505 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
506 return (NULL);
507 }
508
509 data = netconf_opdata(server, conns, session_key, rpc);
510 nc_rpc_free (rpc);
511 return (data);
512}
513
Radek Krejci80c10d92012-07-30 08:38:50 +0200514static char* netconf_get(server_rec* server, apr_hash_t* conns, const char* session_key, const char* filter)
Radek Krejci8e4632a2012-07-26 13:40:34 +0200515{
516 nc_rpc* rpc;
517 struct nc_filter *f = NULL;
518 char* data = NULL;
519
520 /* create filter if set */
521 if (filter != NULL) {
522 f = nc_filter_new(NC_FILTER_SUBTREE, filter);
523 }
524
525 /* create requests */
526 rpc = nc_rpc_get (f);
527 nc_filter_free(f);
528 if (rpc == NULL) {
529 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
530 return (NULL);
531 }
532
533 data = netconf_opdata(server, conns, session_key, rpc);
534 nc_rpc_free (rpc);
535 return (data);
536}
537
Radek Krejci80c10d92012-07-30 08:38:50 +0200538static int netconf_copyconfig(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE source, NC_DATASTORE target, const char* config)
Radek Krejci8e4632a2012-07-26 13:40:34 +0200539{
540 nc_rpc* rpc;
541 int retval = EXIT_SUCCESS;
542
543 /* create requests */
544 rpc = nc_rpc_copyconfig(source, target, config);
545 if (rpc == NULL) {
546 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
547 return (EXIT_FAILURE);
548 }
549
550 retval = netconf_op(server, conns, session_key, rpc);
551 nc_rpc_free (rpc);
552 return (retval);
553}
Radek Krejci035bf4e2012-07-25 10:59:09 +0200554
Radek Krejci80c10d92012-07-30 08:38:50 +0200555static int netconf_editconfig(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE target, NC_EDIT_DEFOP_TYPE defop, NC_EDIT_ERROPT_TYPE erropt, const char* config)
Radek Krejci62ab34b2012-07-26 13:42:05 +0200556{
557 nc_rpc* rpc;
558 int retval = EXIT_SUCCESS;
559
560 /* create requests */
561 rpc = nc_rpc_editconfig(target, defop, erropt, config);
562 if (rpc == NULL) {
563 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
564 return (EXIT_FAILURE);
565 }
566
567 retval = netconf_op(server, conns, session_key, rpc);
568 nc_rpc_free (rpc);
569 return (retval);
570}
571
Radek Krejci80c10d92012-07-30 08:38:50 +0200572static int netconf_killsession(server_rec* server, apr_hash_t* conns, const char* session_key, const char* sid)
Radek Krejcie34d3eb2012-07-26 15:05:53 +0200573{
574 nc_rpc* rpc;
575 int retval = EXIT_SUCCESS;
576
577 /* create requests */
578 rpc = nc_rpc_killsession(sid);
579 if (rpc == NULL) {
580 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
581 return (EXIT_FAILURE);
582 }
583
584 retval = netconf_op(server, conns, session_key, rpc);
585 nc_rpc_free (rpc);
586 return (retval);
587}
588
Radek Krejci80c10d92012-07-30 08:38:50 +0200589static int netconf_onlytargetop(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE target, nc_rpc* (*op_func)(NC_DATASTORE))
Radek Krejci2f318372012-07-26 14:22:35 +0200590{
591 nc_rpc* rpc;
592 int retval = EXIT_SUCCESS;
593
594 /* create requests */
Radek Krejci5cd7d422012-07-26 14:50:29 +0200595 rpc = op_func(target);
Radek Krejci2f318372012-07-26 14:22:35 +0200596 if (rpc == NULL) {
597 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
598 return (EXIT_FAILURE);
599 }
600
601 retval = netconf_op(server, conns, session_key, rpc);
602 nc_rpc_free (rpc);
603 return (retval);
604}
605
Radek Krejci80c10d92012-07-30 08:38:50 +0200606static int netconf_deleteconfig(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE target)
Radek Krejci5cd7d422012-07-26 14:50:29 +0200607{
608 return (netconf_onlytargetop(server, conns, session_key, target, nc_rpc_deleteconfig));
609}
610
Radek Krejci80c10d92012-07-30 08:38:50 +0200611static int netconf_lock(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE target)
Radek Krejci5cd7d422012-07-26 14:50:29 +0200612{
613 return (netconf_onlytargetop(server, conns, session_key, target, nc_rpc_lock));
614}
615
Radek Krejci80c10d92012-07-30 08:38:50 +0200616static int netconf_unlock(server_rec* server, apr_hash_t* conns, const char* session_key, NC_DATASTORE target)
Radek Krejci5cd7d422012-07-26 14:50:29 +0200617{
618 return (netconf_onlytargetop(server, conns, session_key, target, nc_rpc_unlock));
619}
620
Radek Krejci80c10d92012-07-30 08:38:50 +0200621/**
622 * @return REPLY_OK: 0, *data == NULL
623 * REPLY_DATA: 0, *data != NULL
624 * REPLY_ERROR: 1, *data == NULL
625 */
626static int netconf_generic(server_rec* server, apr_hash_t* conns, const char* session_key, const char* content, char** data)
627{
628 struct nc_session *session = NULL;
629 nc_reply* reply;
630 nc_rpc* rpc;
631 int retval = EXIT_SUCCESS;
632
633 /* create requests */
634 rpc = nc_rpc_generic(content);
635 if (rpc == NULL) {
636 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: creating rpc request failed");
637 return (EXIT_FAILURE);
638 }
639
640 *data = NULL;
641
642 /* get session where send the RPC */
643 session = (struct nc_session *)apr_hash_get(conns, session_key, APR_HASH_KEY_STRING);
644 if (session != NULL) {
645 /* send the request and get the reply */
646 nc_session_send_rpc (session, rpc);
647 if (nc_session_recv_reply (session, &reply) == 0) {
648 nc_rpc_free (rpc);
649 if (nc_session_get_status(session) != NC_SESSION_STATUS_WORKING) {
650 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: receiving rpc-reply failed");
651 netconf_close(server, conns, session_key);
652 return (EXIT_FAILURE);
653 }
654
655 /* there is error handled by callback */
656 return (EXIT_FAILURE);
657 }
658 nc_rpc_free (rpc);
659
660 switch (nc_reply_get_type (reply)) {
661 case NC_REPLY_DATA:
662 if ((*data = nc_reply_get_data (reply)) == NULL) {
663 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: no data from reply");
664 return (EXIT_FAILURE);
665 }
666 retval = EXIT_SUCCESS;
667 break;
668 case NC_REPLY_OK:
669 retval = EXIT_SUCCESS;
670 break;
671 default:
672 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "mod_netconf: unexpected rpc-reply");
673 retval = EXIT_FAILURE;
674 break;
675 }
676 nc_reply_free(reply);
677
678 return (retval);
679 } else {
680 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Unknown session to process.");
681 return (EXIT_FAILURE);
682 }
683}
684
Radek Krejci469aab82012-07-22 18:42:20 +0200685server_rec* clb_print_server;
Radek Krejci7338bde2012-08-10 12:57:30 +0200686void clb_print(NC_VERB_LEVEL level, const char* msg)
Radek Krejci469aab82012-07-22 18:42:20 +0200687{
Radek Krejci7338bde2012-08-10 12:57:30 +0200688 switch (level) {
689 case NC_VERB_ERROR:
690 ap_log_error(APLOG_MARK, APLOG_ERR, 0, clb_print_server, msg);
691 break;
692 case NC_VERB_WARNING:
693 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, clb_print_server, msg);
694 break;
695 case NC_VERB_VERBOSE:
696 ap_log_error(APLOG_MARK, APLOG_INFO, 0, clb_print_server, msg);
697 break;
698 case NC_VERB_DEBUG:
699 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, clb_print_server, msg);
700 break;
701 }
Radek Krejci469aab82012-07-22 18:42:20 +0200702}
703
David Kupka8e60a372012-09-04 09:15:20 +0200704void * thread_routine (void * arg)
705{
706 void * retval = NULL;
707
708 ssize_t buffer_len;
709 struct pollfd fds;
710 int status, buffer_size, ret;
711 json_object *request, *reply, *json_obj;
712 int operation;
713 int i, chunk_len;
714 char* session_key, *data;
715 const char *host, *port, *user, *pass;
716 const char *msgtext, *cpbltstr;
717 const char *target, *source, *filter, *config, *defop, *erropt, *sid;
718 struct nc_session *session = NULL;
719 struct nc_cpblts* cpblts;
720 NC_DATASTORE ds_type_s, ds_type_t;
721 NC_EDIT_DEFOP_TYPE defop_type = 0;
722 NC_EDIT_ERROPT_TYPE erropt_type = 0;
723
724 apr_pool_t * pool = ((struct pass_to_thread*)arg)->pool;
725 apr_hash_t *netconf_sessions_list = ((struct pass_to_thread*)arg)->netconf_sessions_list;
726 server_rec * server = ((struct pass_to_thread*)arg)->server;
727 int client = ((struct pass_to_thread*)arg)->client;
728
729 char * buffer, chunk_len_str[12], *chunked_msg;
730 char c;
731
732 while (!isterminated) {
733 fds.fd = client;
734 fds.events = POLLIN;
735 fds.revents = 0;
736
737 status = poll(&fds, 1, 1000);
738
739 if (status == 0 || (status == -1 && (errno == EAGAIN || (errno == EINTR && isterminated == 0)))) {
740 /* poll was interrupted - check if the isterminated is set and if not, try poll again */
741 //ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "poll interrupted");
742 continue;
743 } else if (status < 0) {
744 /* 0: poll time outed
745 * close socket and ignore this request from the client, it can try it again
746 * -1: poll failed
747 * something wrong happend, close this socket and wait for another request
748 */
749 //ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "poll failed, status %d(%d: %s)", status, errno, strerror(errno));
750 close(client);
751 break;
752 }
753 /* status > 0 */
754
755 /* check the status of the socket */
756
757 /* if nothing to read and POLLHUP (EOF) or POLLERR set */
758 if ((fds.revents & POLLHUP) || (fds.revents & POLLERR)) {
759 /* close client's socket (it's probably already closed by client */
760 //ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "socket error (%d)", fds.revents);
761 close(client);
762 break;
763 }
764
765 /* read json in chunked framing */
766 buffer_size = 0;
767 buffer_len = 0;
768 buffer = NULL;
769 while (1) {
770 fds.fd = client;
771 fds.events = POLLIN;
772 fds.revents = 0;
773
774 status = poll(&fds, 1, 1000);
775
776 if (status == 0 || (status == -1 && (errno == EAGAIN || (errno == EINTR && isterminated == 0)))) {
777 /* poll was interrupted - check if the isterminated is set and if not, try poll again */
778 //ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "poll interrupted");
779 continue;
780 } else if (status < 0) {
781 /* 0: poll time outed
782 * close socket and ignore this request from the client, it can try it again
783 * -1: poll failed
784 * something wrong happend, close this socket and wait for another request
785 */
786 //ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "poll failed, status %d(%d: %s)", status, errno, strerror(errno));
787 close(client);
788 break;
789 }
790 /* status > 0 */
791
792 if (buffer != NULL) {
793 request = json_tokener_parse(buffer);
794 operation = json_object_get_int(json_object_object_get(request, "type"));
795
796 session_key = (char*) json_object_get_string(json_object_object_get(request, "session"));
797 /* DO NOT FREE session_key HERE, IT IS PART OF REQUEST */
798 if (operation != MSG_CONNECT && session_key == NULL) {
799 reply = json_object_new_object();
800 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
801 json_object_object_add(reply, "error-message", json_object_new_string("Missing session specification."));
802 msgtext = json_object_to_json_string(reply);
803 send(client, msgtext, strlen(msgtext) + 1, 0);
804 json_object_put(reply);
805 /* there is some stupid client, so close the connection to give a chance to some other client */
806 close(client);
807 break;
808 }
809
810 /* get parameters */
811 ds_type_t = -1;
812 if ((target = json_object_get_string(json_object_object_get(request, "target"))) != NULL) {
813 if (strcmp(target, "running") == 0) {
814 ds_type_t = NC_DATASTORE_RUNNING;
815 } else if (strcmp(target, "startup") == 0) {
816 ds_type_t = NC_DATASTORE_STARTUP;
817 } else if (strcmp(target, "candidate") == 0) {
818 ds_type_t = NC_DATASTORE_CANDIDATE;
819 }
820 }
821 ds_type_s = -1;
822 if ((source = json_object_get_string(json_object_object_get(request, "source"))) != NULL) {
823 if (strcmp(source, "running") == 0) {
824 ds_type_s = NC_DATASTORE_RUNNING;
825 } else if (strcmp(source, "startup") == 0) {
826 ds_type_s = NC_DATASTORE_STARTUP;
827 } else if (strcmp(source, "candidate") == 0) {
828 ds_type_s = NC_DATASTORE_CANDIDATE;
829 }
830 }
831
832 /* null global JSON error-reply */
833 err_reply = NULL;
834
835 /* prepare reply envelope */
836 reply = json_object_new_object();
837
838 /* process required operation */
839 switch (operation) {
840 case MSG_CONNECT:
841 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: Connect");
842
843 host = json_object_get_string(json_object_object_get(request, "host"));
844 port = json_object_get_string(json_object_object_get(request, "port"));
845 user = json_object_get_string(json_object_object_get(request, "user"));
846 pass = json_object_get_string(json_object_object_get(request, "pass"));
847 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "host: %s, port: %s, user: %s", host, port, user);
848 if ((host == NULL) || (user == NULL)) {
849 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Cannot connect - insufficient input.");
850 session_key = NULL;
851 } else {
852 session_key = netconf_connect(server, pool, netconf_sessions_list, host, port, user, pass);
853 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "hash: %s", session_key);
854 }
855
856 reply = json_object_new_object();
857 if (session_key == NULL) {
858 /* negative reply */
859 if (err_reply == NULL) {
860 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
861 json_object_object_add(reply, "error-message", json_object_new_string("Connecting NETCONF server failed."));
862 } else {
863 /* use filled err_reply from libnetconf's callback */
864 json_object_put(reply);
865 reply = err_reply;
866 }
867 } else {
868 /* positive reply */
869 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
870 json_object_object_add(reply, "session", json_object_new_string(session_key));
871
872 free(session_key);
873 }
874
875 break;
876 case MSG_GET:
877 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: get (session %s)", session_key);
878
879 filter = json_object_get_string(json_object_object_get(request, "filter"));
880
881 //ap_log_error (APLOG_MARK, APLOG_ERR, 0, server, "get filter: %p", filter);
882
883 if ((data = netconf_get(server, netconf_sessions_list, session_key, NULL)) == NULL) {
884 if (err_reply == NULL) {
885 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
886 json_object_object_add(reply, "error-message", json_object_new_string("get failed."));
887 } else {
888 /* use filled err_reply from libnetconf's callback */
889 json_object_put(reply);
890 reply = err_reply;
891 }
892 } else {
893 json_object_object_add(reply, "type", json_object_new_int(REPLY_DATA));
894 json_object_object_add(reply, "data", json_object_new_string(data));
895 }
896 break;
897 case MSG_GETCONFIG:
898 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: get-config (session %s)", session_key);
899
900 filter = json_object_get_string(json_object_object_get(request, "filter"));
901
902 if (ds_type_s == -1) {
903 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
904 json_object_object_add(reply, "error-message", json_object_new_string("Invalid source repository type requested."));
905 break;
906 }
907
908 if ((data = netconf_getconfig(server, netconf_sessions_list, session_key, ds_type_s, filter)) == NULL) {
909 if (err_reply == NULL) {
910 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
911 json_object_object_add(reply, "error-message", json_object_new_string("get-config failed."));
912 } else {
913 /* use filled err_reply from libnetconf's callback */
914 json_object_put(reply);
915 reply = err_reply;
916 }
917 } else {
918 json_object_object_add(reply, "type", json_object_new_int(REPLY_DATA));
919 json_object_object_add(reply, "data", json_object_new_string(data));
920 }
921 break;
922 case MSG_EDITCONFIG:
923 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: edit-config (session %s)", session_key);
924
925 defop = json_object_get_string(json_object_object_get(request, "default-operation"));
926 if (defop != NULL) {
927 if (strcmp(defop, "merge") == 0) {
928 defop_type = NC_EDIT_DEFOP_MERGE;
929 } else if (strcmp(defop, "replace") == 0) {
930 defop_type = NC_EDIT_DEFOP_REPLACE;
931 } else if (strcmp(defop, "none") == 0) {
932 defop_type = NC_EDIT_DEFOP_NONE;
933 } else {
934 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
935 json_object_object_add(reply, "error-message", json_object_new_string("Invalid default-operation parameter."));
936 break;
937 }
938 } else {
939 defop_type = 0;
940 }
941
942 erropt = json_object_get_string(json_object_object_get(request, "error-option"));
943 if (erropt != NULL) {
944 if (strcmp(erropt, "continue-on-error") == 0) {
945 erropt_type = NC_EDIT_ERROPT_CONT;
946 } else if (strcmp(erropt, "stop-on-error") == 0) {
947 erropt_type = NC_EDIT_ERROPT_STOP;
948 } else if (strcmp(erropt, "rollback-on-error") == 0) {
949 erropt_type = NC_EDIT_ERROPT_ROLLBACK;
950 } else {
951 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
952 json_object_object_add(reply, "error-message", json_object_new_string("Invalid error-option parameter."));
953 break;
954 }
955 } else {
956 erropt_type = 0;
957 }
958
959 if (ds_type_t == -1) {
960 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
961 json_object_object_add(reply, "error-message", json_object_new_string("Invalid target repository type requested."));
962 break;
963 }
964
965 config = json_object_get_string(json_object_object_get(request, "config"));
966 if (config == NULL) {
967 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
968 json_object_object_add(reply, "error-message", json_object_new_string("Invalid config data parameter."));
969 break;
970 }
971
972 if (netconf_editconfig(server, netconf_sessions_list, session_key, ds_type_t, defop_type, erropt_type, config) != EXIT_SUCCESS) {
973 if (err_reply == NULL) {
974 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
975 json_object_object_add(reply, "error-message", json_object_new_string("edit-config failed."));
976 } else {
977 /* use filled err_reply from libnetconf's callback */
978 json_object_put(reply);
979 reply = err_reply;
980 }
981 } else {
982 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
983 }
984 break;
985 case MSG_COPYCONFIG:
986 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: copy-config (session %s)", session_key);
987 config = NULL;
988
989 if (source == NULL) {
990 /* no explicit source specified -> use config data */
991 ds_type_s = NC_DATASTORE_NONE;
992 config = json_object_get_string(json_object_object_get(request, "config"));
993 } else if (ds_type_s == -1) {
994 /* source datastore specified, but it is invalid */
995 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
996 json_object_object_add(reply, "error-message", json_object_new_string("Invalid source repository type requested."));
997 break;
998 }
999
1000 if (ds_type_t == -1) {
1001 /* invalid target datastore specified */
1002 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1003 json_object_object_add(reply, "error-message", json_object_new_string("Invalid target repository type requested."));
1004 break;
1005 }
1006
1007 if (source == NULL && config == NULL) {
1008 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1009 json_object_object_add(reply, "error-message", json_object_new_string("invalid input parameters - one of source and config is required."));
1010 } else {
1011 if (netconf_copyconfig(server, netconf_sessions_list, session_key, ds_type_s, ds_type_t, config) != EXIT_SUCCESS) {
1012 if (err_reply == NULL) {
1013 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1014 json_object_object_add(reply, "error-message", json_object_new_string("copy-config failed."));
1015 } else {
1016 /* use filled err_reply from libnetconf's callback */
1017 json_object_put(reply);
1018 reply = err_reply;
1019 }
1020 } else {
1021 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
1022 }
1023 }
1024 break;
1025 case MSG_DELETECONFIG:
1026 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: delete-config (session %s)", session_key);
1027 /* no break - unifying code */
1028 case MSG_LOCK:
1029 if (operation == MSG_LOCK) {
1030 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: lock (session %s)", session_key);
1031 }
1032 /* no break - unifying code */
1033 case MSG_UNLOCK:
1034 if (operation == MSG_UNLOCK) {
1035 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: unlock (session %s)", session_key);
1036 }
1037
1038 if (ds_type_t == -1) {
1039 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1040 json_object_object_add(reply, "error-message", json_object_new_string("Invalid target repository type requested."));
1041 break;
1042 }
1043
1044 switch(operation) {
1045 case MSG_DELETECONFIG:
1046 status = netconf_deleteconfig(server, netconf_sessions_list, session_key, ds_type_t);
1047 break;
1048 case MSG_LOCK:
1049 status = netconf_lock(server, netconf_sessions_list, session_key, ds_type_t);
1050 break;
1051 case MSG_UNLOCK:
1052 status = netconf_unlock(server, netconf_sessions_list, session_key, ds_type_t);
1053 break;
1054 default:
1055 status = -1;
1056 break;
1057 }
1058
1059 if (status != EXIT_SUCCESS) {
1060 if (err_reply == NULL) {
1061 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1062 json_object_object_add(reply, "error-message", json_object_new_string("operation failed."));
1063 } else {
1064 /* use filled err_reply from libnetconf's callback */
1065 json_object_put(reply);
1066 reply = err_reply;
1067 }
1068 } else {
1069 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
1070 }
1071 break;
1072 case MSG_KILL:
1073 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: kill-session, session %s", session_key);
1074
1075 sid = json_object_get_string(json_object_object_get(request, "session-id"));
1076
1077 if (sid == NULL) {
1078 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1079 json_object_object_add(reply, "error-message", json_object_new_string("Missing session-id parameter."));
1080 break;
1081 }
1082
1083 if (netconf_killsession(server, netconf_sessions_list, session_key, sid) != EXIT_SUCCESS) {
1084 if (err_reply == NULL) {
1085 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1086 json_object_object_add(reply, "error-message", json_object_new_string("kill-session failed."));
1087 } else {
1088 /* use filled err_reply from libnetconf's callback */
1089 json_object_put(reply);
1090 reply = err_reply;
1091 }
1092 } else {
1093 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
1094 }
1095 break;
1096 case MSG_DISCONNECT:
1097 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: Disconnect session %s", session_key);
1098
1099 if (netconf_close(server, netconf_sessions_list, session_key) != EXIT_SUCCESS) {
1100 if (err_reply == NULL) {
1101 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1102 json_object_object_add(reply, "error-message", json_object_new_string("Invalid session identifier."));
1103 } else {
1104 /* use filled err_reply from libnetconf's callback */
1105 json_object_put(reply);
1106 reply = err_reply;
1107 }
1108 } else {
1109 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
1110 }
1111 break;
1112 case MSG_INFO:
1113 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: get info about session %s", session_key);
1114
1115 session = (struct nc_session *)apr_hash_get(netconf_sessions_list, session_key, APR_HASH_KEY_STRING);
1116 if (session != NULL) {
1117 json_object_object_add(reply, "sid", json_object_new_string(nc_session_get_id(session)));
1118 json_object_object_add(reply, "version", json_object_new_string((nc_session_get_version(session) == 0)?"1.0":"1.1"));
1119 json_object_object_add(reply, "host", json_object_new_string(nc_session_get_host(session)));
1120 json_object_object_add(reply, "port", json_object_new_string(nc_session_get_port(session)));
1121 json_object_object_add(reply, "user", json_object_new_string(nc_session_get_user(session)));
1122 cpblts = nc_session_get_cpblts (session);
1123 if (cpblts != NULL) {
1124 json_obj = json_object_new_array();
1125 nc_cpblts_iter_start (cpblts);
1126 while ((cpbltstr = nc_cpblts_iter_next (cpblts)) != NULL) {
1127 json_object_array_add(json_obj, json_object_new_string(cpbltstr));
1128 }
1129 json_object_object_add(reply, "capabilities", json_obj);
1130 }
1131 } else {
1132 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1133 json_object_object_add(reply, "error-message", json_object_new_string("Invalid session identifier."));
1134 }
1135
1136 break;
1137 case MSG_GENERIC:
1138 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "Request: generic request for session %s", session_key);
1139
1140 config = json_object_get_string(json_object_object_get(request, "content"));
1141
1142 if (config == NULL) {
1143 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1144 json_object_object_add(reply, "error-message", json_object_new_string("Missing content parameter."));
1145 break;
1146 }
1147
1148 if (netconf_generic(server, netconf_sessions_list, session_key, config, &data) != EXIT_SUCCESS) {
1149 if (err_reply == NULL) {
1150 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1151 json_object_object_add(reply, "error-message", json_object_new_string("kill-session failed."));
1152 } else {
1153 /* use filled err_reply from libnetconf's callback */
1154 json_object_put(reply);
1155 reply = err_reply;
1156 }
1157 } else {
1158 if (data == NULL) {
1159 json_object_object_add(reply, "type", json_object_new_int(REPLY_OK));
1160 } else {
1161 json_object_object_add(reply, "type", json_object_new_int(REPLY_DATA));
1162 json_object_object_add(reply, "data", json_object_new_string(data));
1163 }
1164 }
1165 break;
1166 default:
1167 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Unknown mod_netconf operation requested (%d)", operation);
1168 reply = json_object_new_object();
1169 json_object_object_add(reply, "type", json_object_new_int(REPLY_ERROR));
1170 json_object_object_add(reply, "error-message", json_object_new_string("Operation not supported."));
1171 break;
1172 }
1173 json_object_put(request);
1174
1175 /* send reply to caller */
1176 if (reply != NULL) {
1177 msgtext = json_object_to_json_string(reply);
1178 send(client, msgtext, strlen(msgtext) + 1, 0);
1179 json_object_put(reply);
1180 } else {
1181 break;
1182 }
1183 }
1184 }
1185 }
1186
1187 free (arg);
1188
1189 return retval;
1190}
1191
Radek Krejcif23850c2012-07-23 16:14:17 +02001192/*
1193 * This is actually implementation of NETCONF client
1194 * - requests are received from UNIX socket in the predefined format
1195 * - results are replied through the same way
1196 * - the daemon run as a separate process, but it is started and stopped
1197 * automatically by Apache.
1198 *
1199 */
Radek Krejci469aab82012-07-22 18:42:20 +02001200static void forked_proc(apr_pool_t * pool, server_rec * server)
1201{
1202 struct sockaddr_un local, remote;
David Kupka8e60a372012-09-04 09:15:20 +02001203 int lsock, client, ret, i, pthread_count = 0;
1204 socklen_t len;
Radek Krejciae021c12012-07-25 18:03:52 +02001205 mod_netconf_cfg *cfg;
Radek Krejci469aab82012-07-22 18:42:20 +02001206 apr_hash_t *netconf_sessions_list;
David Kupka8e60a372012-09-04 09:15:20 +02001207 struct pass_to_thread * arg;
1208 pthread_t * ptids = calloc (1,sizeof(pthread_t));
1209 struct timespec maxtime;
1210 pthread_rwlockattr_t lock_attrs;
1211
1212 /* wait at most 5 secons for every thread to terminate */
1213 maxtime.tv_sec = 5;
1214 maxtime.tv_nsec = 0;
Radek Krejci469aab82012-07-22 18:42:20 +02001215
Radek Krejcif23850c2012-07-23 16:14:17 +02001216 /* change uid and gid of process for security reasons */
Radek Krejci469aab82012-07-22 18:42:20 +02001217 unixd_setup_child();
1218
Radek Krejciae021c12012-07-25 18:03:52 +02001219 cfg = ap_get_module_config(server->module_config, &netconf_module);
1220 if (cfg == NULL) {
Radek Krejci8fd1f5e2012-07-24 17:33:36 +02001221 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Getting mod_netconf configuration failed");
1222 return;
1223 }
Radek Krejci469aab82012-07-22 18:42:20 +02001224
Radek Krejci8fd1f5e2012-07-24 17:33:36 +02001225 /* create listening UNIX socket to accept incoming connections */
Radek Krejci469aab82012-07-22 18:42:20 +02001226 if ((lsock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
1227 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Creating socket failed (%s)", strerror(errno));
1228 return;
1229 }
1230
1231 local.sun_family = AF_UNIX;
Radek Krejciae021c12012-07-25 18:03:52 +02001232 strncpy(local.sun_path, cfg->sockname, sizeof(local.sun_path));
Radek Krejci469aab82012-07-22 18:42:20 +02001233 unlink(local.sun_path);
1234 len = offsetof(struct sockaddr_un, sun_path) + strlen(local.sun_path);
1235
1236 if (bind(lsock, (struct sockaddr *) &local, len) == -1) {
1237 if (errno == EADDRINUSE) {
1238 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "mod_netconf socket address already in use");
1239 close(lsock);
1240 exit(0);
1241 }
1242 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Binding socket failed (%s)", strerror(errno));
1243 close(lsock);
1244 return;
1245 }
1246
1247 if (listen(lsock, MAX_SOCKET_CL) == -1) {
1248 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Setting up listen socket failed (%s)", strerror(errno));
1249 close(lsock);
1250 return;
1251 }
1252
1253 /* prepare internal lists */
1254 netconf_sessions_list = apr_hash_make(pool);
1255
1256 /* setup libnetconf's callbacks */
1257 nc_verbosity(NC_VERB_DEBUG);
1258 clb_print_server = server;
1259 nc_callback_print(clb_print);
1260 nc_callback_ssh_host_authenticity_check(netconf_callback_ssh_hostkey_check);
1261 nc_callback_sshauth_interactive(netconf_callback_sshauth_interactive);
1262 nc_callback_sshauth_password(netconf_callback_sshauth_password);
Radek Krejcic11fd862012-07-26 12:41:21 +02001263 nc_callback_error_reply(netconf_callback_error_process);
Radek Krejci469aab82012-07-22 18:42:20 +02001264
1265 /* disable publickey authentication */
1266 nc_ssh_pref(NC_SSH_AUTH_PUBLIC_KEYS, -1);
1267
David Kupka8e60a372012-09-04 09:15:20 +02001268 /* create mutex protecting session list */
1269 pthread_rwlockattr_init(&lock_attrs);
1270 /* rwlock is shared only with threads in this process */
1271 pthread_rwlockattr_setpshared(&lock_attrs, PTHREAD_PROCESS_PRIVATE);
1272 /* create rw lock */
1273 if (pthread_rwlock_init(&session_lock, &lock_attrs) != 0) {
1274 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Initialization of mutex failed: %d (%s)", errno, strerror(errno));
1275 close (lsock);
1276 return;
1277 }
1278
Radek Krejci469aab82012-07-22 18:42:20 +02001279 while (isterminated == 0) {
1280 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "waiting for another client's request");
1281
1282 /* open incoming connection if any */
David Kupka8e60a372012-09-04 09:15:20 +02001283 len = sizeof(remote);
1284 client = accept(lsock, (struct sockaddr *) &remote, &len);
Radek Krejci469aab82012-07-22 18:42:20 +02001285 if (client == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
1286 apr_sleep(SLEEP_TIME);
1287 continue;
1288 } else if (client == -1 && (errno == EINTR)) {
1289 continue;
1290 } else if (client == -1) {
1291 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Accepting mod_netconf client connection failed (%s)", strerror(errno));
1292 continue;
1293 }
Radek Krejci469aab82012-07-22 18:42:20 +02001294
1295 /* set client's socket as non-blocking */
Radek Krejcif23850c2012-07-23 16:14:17 +02001296 //fcntl(client, F_SETFL, fcntl(client, F_GETFL, 0) | O_NONBLOCK);
Radek Krejci469aab82012-07-22 18:42:20 +02001297
David Kupka8e60a372012-09-04 09:15:20 +02001298 arg = malloc (sizeof(struct pass_to_thread));
1299 arg->client = client;
1300 arg->pool = pool;
1301 arg->server = server;
1302 arg->netconf_sessions_list = netconf_sessions_list;
Radek Krejci469aab82012-07-22 18:42:20 +02001303
David Kupka8e60a372012-09-04 09:15:20 +02001304 /* start new thread. It will serve this particular request and then terminate */
1305 if ((ret = pthread_create (&ptids[pthread_count], NULL, thread_routine, (void*)arg)) != 0) {
1306 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Creating POSIX thread failed: %d\n", ret);
1307 } else {
1308 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Thread %lu created", ptids[pthread_count]);
1309 pthread_count++;
1310 ptids = realloc (ptids, sizeof(pthread_t)*(pthread_count+1));
1311 ptids[pthread_count] = 0;
1312 }
Radek Krejci469aab82012-07-22 18:42:20 +02001313
David Kupka8e60a372012-09-04 09:15:20 +02001314 /* check if some thread already terminated, free some resources by joining it */
1315 for (i=0; i<pthread_count; i++) {
1316 if (pthread_tryjoin_np (ptids[i], (void**)&arg) == 0) {
1317 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Thread %lu joined with retval %p", ptids[i], arg);
1318 pthread_count--;
1319 if (pthread_count > 0) {
1320 /* place last Thread ID on the place of joined one */
1321 ptids[i] = ptids[pthread_count];
Radek Krejci8fd1f5e2012-07-24 17:33:36 +02001322 }
Radek Krejci469aab82012-07-22 18:42:20 +02001323 }
1324 }
David Kupka8e60a372012-09-04 09:15:20 +02001325 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Running %d threads", pthread_count);
Radek Krejci469aab82012-07-22 18:42:20 +02001326 }
1327
David Kupka8e60a372012-09-04 09:15:20 +02001328 /* join all threads */
1329 for (i=0; i<pthread_count; i++) {
1330 pthread_timedjoin_np (ptids[i], (void**)&arg, &maxtime);
1331 }
1332 free (ptids);
1333
Radek Krejci469aab82012-07-22 18:42:20 +02001334 close(lsock);
1335
David Kupka8e60a372012-09-04 09:15:20 +02001336 /* destroy rwlock */
1337 pthread_rwlock_destroy(&session_lock);
1338 pthread_rwlockattr_destroy(&lock_attrs);
1339
Radek Krejci469aab82012-07-22 18:42:20 +02001340 ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "Exiting from the mod_netconf daemon");
1341
1342 exit(APR_SUCCESS);
1343}
1344
Radek Krejcif23850c2012-07-23 16:14:17 +02001345static void *mod_netconf_create_conf(apr_pool_t * pool, server_rec * s)
Radek Krejci469aab82012-07-22 18:42:20 +02001346{
Radek Krejcif23850c2012-07-23 16:14:17 +02001347 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "Init netconf module config");
1348
1349 mod_netconf_cfg *config = apr_pcalloc(pool, sizeof(mod_netconf_cfg));
1350 apr_pool_create(&config->pool, pool);
1351 config->forkproc = NULL;
Radek Krejci8fd1f5e2012-07-24 17:33:36 +02001352 config->sockname = SOCKET_FILENAME;
Radek Krejcif23850c2012-07-23 16:14:17 +02001353
1354 return (void *)config;
Radek Krejci469aab82012-07-22 18:42:20 +02001355}
1356
1357static int mod_netconf_master_init(apr_pool_t * pconf, apr_pool_t * ptemp,
1358 apr_pool_t * plog, server_rec * s)
1359{
Radek Krejcif23850c2012-07-23 16:14:17 +02001360 mod_netconf_cfg *config;
1361 apr_status_t res;
1362
Radek Krejci469aab82012-07-22 18:42:20 +02001363 /* These two help ensure that we only init once. */
1364 void *data;
Radek Krejcif23850c2012-07-23 16:14:17 +02001365 const char *userdata_key = "netconf_ipc_init";
Radek Krejci469aab82012-07-22 18:42:20 +02001366
1367 /*
1368 * The following checks if this routine has been called before.
1369 * This is necessary because the parent process gets initialized
1370 * a couple of times as the server starts up.
1371 */
1372 apr_pool_userdata_get(&data, userdata_key, s->process->pool);
1373 if (!data) {
1374 apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
1375 return (OK);
1376 }
1377
Radek Krejcif23850c2012-07-23 16:14:17 +02001378 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "creating mod_netconf daemon");
1379 config = ap_get_module_config(s->module_config, &netconf_module);
Radek Krejcidfaa6ea2012-07-23 09:04:43 +02001380
Radek Krejcif23850c2012-07-23 16:14:17 +02001381 if (config && config->forkproc == NULL) {
1382 config->forkproc = apr_pcalloc(config->pool, sizeof(apr_proc_t));
1383 res = apr_proc_fork(config->forkproc, config->pool);
Radek Krejci469aab82012-07-22 18:42:20 +02001384 switch (res) {
1385 case APR_INCHILD:
1386 /* set signal handler */
Radek Krejcif23850c2012-07-23 16:14:17 +02001387 apr_signal_init(config->pool);
Radek Krejci469aab82012-07-22 18:42:20 +02001388 apr_signal(SIGTERM, signal_handler);
1389
1390 /* log start of the separated NETCONF communication process */
Radek Krejcif23850c2012-07-23 16:14:17 +02001391 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, "mod_netconf daemon started (PID %d)", getpid());
Radek Krejci469aab82012-07-22 18:42:20 +02001392
1393 /* start main loop providing NETCONF communication */
Radek Krejcif23850c2012-07-23 16:14:17 +02001394 forked_proc(config->pool, s);
Radek Krejci469aab82012-07-22 18:42:20 +02001395
Radek Krejcif23850c2012-07-23 16:14:17 +02001396 /* I never should be here, wtf?!? */
1397 ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_netconf daemon unexpectedly stopped");
Radek Krejci469aab82012-07-22 18:42:20 +02001398 exit(APR_EGENERAL);
1399 break;
1400 case APR_INPARENT:
1401 /* register child to be killed (SIGTERM) when the module config's pool dies */
Radek Krejcif23850c2012-07-23 16:14:17 +02001402 apr_pool_note_subprocess(config->pool, config->forkproc, APR_KILL_AFTER_TIMEOUT);
Radek Krejci469aab82012-07-22 18:42:20 +02001403 break;
1404 default:
1405 ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "apr_proc_fork() failed");
1406 break;
1407 }
Radek Krejcif23850c2012-07-23 16:14:17 +02001408 } else {
1409 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_netconf misses configuration structure");
Radek Krejci469aab82012-07-22 18:42:20 +02001410 }
1411
1412 return OK;
1413}
1414
Radek Krejci469aab82012-07-22 18:42:20 +02001415/**
1416 * Register module hooks
1417 */
1418static void mod_netconf_register_hooks(apr_pool_t * p)
1419{
Radek Krejcif23850c2012-07-23 16:14:17 +02001420 ap_hook_post_config(mod_netconf_master_init, NULL, NULL, APR_HOOK_LAST);
Radek Krejci469aab82012-07-22 18:42:20 +02001421}
1422
Radek Krejci8fd1f5e2012-07-24 17:33:36 +02001423static const char* cfg_set_socket_path(cmd_parms* cmd, void* cfg, const char* arg)
1424{
1425 ((mod_netconf_cfg*)cfg)->sockname = apr_pstrdup(cmd->pool, arg);
1426 return NULL;
1427}
1428
1429static const command_rec netconf_cmds[] = {
1430 AP_INIT_TAKE1("NetconfSocket", cfg_set_socket_path, NULL, OR_ALL, "UNIX socket path for mod_netconf communication."),
1431 {NULL}
1432};
1433
Radek Krejci469aab82012-07-22 18:42:20 +02001434/* Dispatch list for API hooks */
1435module AP_MODULE_DECLARE_DATA netconf_module = {
1436 STANDARD20_MODULE_STUFF,
1437 NULL, /* create per-dir config structures */
1438 NULL, /* merge per-dir config structures */
Radek Krejcif23850c2012-07-23 16:14:17 +02001439 mod_netconf_create_conf, /* create per-server config structures */
Radek Krejci469aab82012-07-22 18:42:20 +02001440 NULL, /* merge per-server config structures */
Radek Krejci8fd1f5e2012-07-24 17:33:36 +02001441 netconf_cmds, /* table of config file commands */
Radek Krejci469aab82012-07-22 18:42:20 +02001442 mod_netconf_register_hooks /* register hooks */
1443};