ryzhov_al

inadyn: 1.99.15 vs Padavan

Jan 22nd, 2016
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 129.30 KB | None | 0 0
  1. diff -urN ./inadyn-1.99.15/include/base64.h ./inadyn_padavan/include/base64.h
  2. --- ./inadyn-1.99.15/include/base64.h   2016-01-22 13:41:47.000000000 +0300
  3. +++ ./inadyn_padavan/include/base64.h   2016-01-22 14:22:01.000000000 +0300
  4. @@ -29,7 +29,6 @@
  5.  #ifndef BASE64_H
  6.  #define BASE64_H
  7.  
  8. -#include <stdint.h>
  9.  #include <string.h>
  10.  
  11.  #define ERR_BASE64_BUFFER_TOO_SMALL               -0x002A  /**< Output buffer too small. */
  12. diff -urN ./inadyn-1.99.15/include/ddns.h ./inadyn_padavan/include/ddns.h
  13. --- ./inadyn-1.99.15/include/ddns.h     2016-01-22 13:41:48.000000000 +0300
  14. +++ ./inadyn_padavan/include/ddns.h     2016-01-22 14:22:01.000000000 +0300
  15. @@ -24,24 +24,20 @@
  16.  #ifndef DYNDNS_H_
  17.  #define DYNDNS_H_
  18.  
  19. -#include <paths.h>
  20. -
  21. -#include "config.h"
  22.  #include "os.h"
  23.  #include "error.h"
  24.  #include "http.h"
  25.  #include "debug.h"
  26.  #include "plugin.h"
  27. -#include "libite/lite.h"
  28.  
  29.  #define VERSION_STRING "Inadyn version " VERSION " -- Dynamic DNS update client."
  30.  #define AGENT_NAME     "inadyn/" VERSION
  31. -#define SUPPORT_ADDR   PACKAGE_BUGREPORT
  32. +#define SUPPORT_ADDR   "troglobit@gmail.com"
  33.  
  34.  /* Test values */
  35.  #define DEFAULT_CONFIG_FILE    "/etc/inadyn.conf"
  36. -#define RUNTIME_DATA_DIR        _PATH_VARRUN     "inadyn/"
  37. -#define DEFAULT_PIDFILE         RUNTIME_DATA_DIR "inadyn.pid"
  38. +#define RUNTIME_DATA_DIR       "/var/run"
  39. +#define DEFAULT_PIDFILE                RUNTIME_DATA_DIR "/inadyn.pid"
  40.  
  41.  #define DYNDNS_MY_IP_SERVER    "checkip.dyndns.org"
  42.  #define DYNDNS_MY_CHECKIP_URL  "/"
  43. @@ -57,16 +53,17 @@
  44.  /* Some default configurations */
  45.  #define DYNDNS_DEFAULT_STARTUP_SLEEP      0       /* sec */
  46.  #define DYNDNS_DEFAULT_SLEEP              120     /* sec */
  47. -#define DYNDNS_MIN_SLEEP                  30      /* sec */
  48. +#define DYNDNS_MIN_SLEEP                  3       /* sec */
  49.  #define DYNDNS_MAX_SLEEP                  (10 * 24 * 3600)        /* 10 days in sec */
  50.  #define DYNDNS_ERROR_UPDATE_PERIOD        600     /* 10 min */
  51. -#define DYNDNS_FORCED_UPDATE_PERIOD       (30 * 24 * 3600)        /* 30 days in sec */
  52. +#define DYNDNS_FAILED_UPDATE_PERIOD       300     /* 5 min */
  53. +#define DYNDNS_FORCED_UPDATE_PERIOD       (10 * 24 * 3600)        /* 10 days in sec */
  54.  #define DYNDNS_DEFAULT_CMD_CHECK_PERIOD   1       /* sec */
  55.  #define DYNDNS_DEFAULT_ITERATIONS         0       /* Forever */
  56.  #define DYNDNS_HTTP_RESPONSE_BUFFER_SIZE  2500    /* Bytes */
  57.  #define DYNDNS_HTTP_REQUEST_BUFFER_SIZE   2500    /* Bytes */
  58. -#define DYNDNS_MAX_ALIAS_NUMBER           10      /* maximum number of aliases per server that can be maintained */
  59. -#define DYNDNS_MAX_SERVER_NUMBER          5       /* maximum number of servers that can be maintained */
  60. +#define DYNDNS_MAX_ALIAS_NUMBER           5       /* maximum number of aliases per server that can be maintained */
  61. +#define DYNDNS_MAX_SERVER_NUMBER          3       /* maximum number of servers that can be maintained */
  62.  
  63.  /* local configs */
  64.  #define USERNAME_LEN                      50      /* chars */
  65. diff -urN ./inadyn-1.99.15/include/http.h ./inadyn_padavan/include/http.h
  66. --- ./inadyn-1.99.15/include/http.h     2016-01-22 13:41:48.000000000 +0300
  67. +++ ./inadyn_padavan/include/http.h     2016-01-22 14:22:01.000000000 +0300
  68. @@ -21,8 +21,6 @@
  69.  #ifndef INADYN_HTTP_H_
  70.  #define INADYN_HTTP_H_
  71.  
  72. -#include "config.h"
  73. -
  74.  #if defined(CONFIG_OPENSSL)
  75.  #include <openssl/crypto.h>
  76.  #include <openssl/x509.h>
  77. @@ -30,11 +28,6 @@
  78.  #include <openssl/ssl.h>
  79.  #include <openssl/tls1.h>
  80.  #include <openssl/err.h>
  81. -#elif defined(CONFIG_GNUTLS)
  82. -#include <gnutls/openssl.h>
  83. -/* Missing OpenSSL wrappers */
  84. -#define ERR_free_strings()
  85. -#define OPENSSL_free(ptr)     free(ptr)
  86.  #endif
  87.  
  88.  #include "error.h"
  89. @@ -42,7 +35,8 @@
  90.  #include "tcp.h"
  91.  
  92.  #define HTTP_DEFAULT_TIMEOUT   10000   /* msec */
  93. -#define        HTTP_DEFAULT_PORT       80
  94. +#define HTTP_DEFAULT_PORT      80
  95. +#define HTTPS_DEFAULT_PORT     443
  96.  
  97.  typedef struct {
  98.         tcp_sock_t tcp;
  99. @@ -54,6 +48,7 @@
  100.  #endif
  101.  
  102.         int        initialized;
  103. +       int        verbose;
  104.  } http_t;
  105.  
  106.  typedef struct {
  107. diff -urN ./inadyn-1.99.15/include/md5.h ./inadyn_padavan/include/md5.h
  108. --- ./inadyn-1.99.15/include/md5.h      2016-01-22 13:41:47.000000000 +0300
  109. +++ ./inadyn_padavan/include/md5.h      2016-01-22 14:22:01.000000000 +0300
  110. @@ -29,7 +29,6 @@
  111.  #ifndef MD5_H
  112.  #define MD5_H
  113.  
  114. -#include <stdint.h>
  115.  #include <string.h>
  116.  
  117.  /**
  118. diff -urN ./inadyn-1.99.15/include/plugin.h ./inadyn_padavan/include/plugin.h
  119. --- ./inadyn-1.99.15/include/plugin.h   2016-01-22 13:41:47.000000000 +0300
  120. +++ ./inadyn_padavan/include/plugin.h   2016-01-22 14:22:01.000000000 +0300
  121. @@ -24,7 +24,7 @@
  122.  #ifndef INADYN_PLUGIN_H_
  123.  #define INADYN_PLUGIN_H_
  124.  
  125. -#include "libite/queue.h"      /* BSD sys/queue.h API */
  126. +#include "queue.h"             /* BSD sys/queue.h API */
  127.  
  128.  #define GENERIC_HTTP_REQUEST                                           \
  129.         "GET %s HTTP/1.0\r\n"                                           \
  130. diff -urN ./inadyn-1.99.15/include/queue.h ./inadyn_padavan/include/queue.h
  131. --- ./inadyn-1.99.15/include/queue.h    1970-01-01 03:00:00.000000000 +0300
  132. +++ ./inadyn_padavan/include/queue.h    2016-01-22 14:22:01.000000000 +0300
  133. @@ -0,0 +1,568 @@
  134. +/*     $OpenBSD: queue.h,v 1.36 2012/04/11 13:29:14 naddy Exp $        */
  135. +/*     $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $       */
  136. +
  137. +/*
  138. + * Copyright (c) 1991, 1993
  139. + *     The Regents of the University of California.  All rights reserved.
  140. + *
  141. + * Redistribution and use in source and binary forms, with or without
  142. + * modification, are permitted provided that the following conditions
  143. + * are met:
  144. + * 1. Redistributions of source code must retain the above copyright
  145. + *    notice, this list of conditions and the following disclaimer.
  146. + * 2. Redistributions in binary form must reproduce the above copyright
  147. + *    notice, this list of conditions and the following disclaimer in the
  148. + *    documentation and/or other materials provided with the distribution.
  149. + * 3. Neither the name of the University nor the names of its contributors
  150. + *    may be used to endorse or promote products derived from this software
  151. + *    without specific prior written permission.
  152. + *
  153. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  154. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  155. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  156. + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  157. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  158. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  159. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  160. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  161. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  162. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  163. + * SUCH DAMAGE.
  164. + *
  165. + *     @(#)queue.h     8.5 (Berkeley) 8/20/94
  166. + */
  167. +
  168. +#ifndef        _SYS_QUEUE_H_
  169. +#define        _SYS_QUEUE_H_
  170. +
  171. +/*
  172. + * This file defines five types of data structures: singly-linked lists,
  173. + * lists, simple queues, tail queues, and circular queues.
  174. + *
  175. + *
  176. + * A singly-linked list is headed by a single forward pointer. The elements
  177. + * are singly linked for minimum space and pointer manipulation overhead at
  178. + * the expense of O(n) removal for arbitrary elements. New elements can be
  179. + * added to the list after an existing element or at the head of the list.
  180. + * Elements being removed from the head of the list should use the explicit
  181. + * macro for this purpose for optimum efficiency. A singly-linked list may
  182. + * only be traversed in the forward direction.  Singly-linked lists are ideal
  183. + * for applications with large datasets and few or no removals or for
  184. + * implementing a LIFO queue.
  185. + *
  186. + * A list is headed by a single forward pointer (or an array of forward
  187. + * pointers for a hash table header). The elements are doubly linked
  188. + * so that an arbitrary element can be removed without a need to
  189. + * traverse the list. New elements can be added to the list before
  190. + * or after an existing element or at the head of the list. A list
  191. + * may only be traversed in the forward direction.
  192. + *
  193. + * A simple queue is headed by a pair of pointers, one the head of the
  194. + * list and the other to the tail of the list. The elements are singly
  195. + * linked to save space, so elements can only be removed from the
  196. + * head of the list. New elements can be added to the list before or after
  197. + * an existing element, at the head of the list, or at the end of the
  198. + * list. A simple queue may only be traversed in the forward direction.
  199. + *
  200. + * A tail queue is headed by a pair of pointers, one to the head of the
  201. + * list and the other to the tail of the list. The elements are doubly
  202. + * linked so that an arbitrary element can be removed without a need to
  203. + * traverse the list. New elements can be added to the list before or
  204. + * after an existing element, at the head of the list, or at the end of
  205. + * the list. A tail queue may be traversed in either direction.
  206. + *
  207. + * A circle queue is headed by a pair of pointers, one to the head of the
  208. + * list and the other to the tail of the list. The elements are doubly
  209. + * linked so that an arbitrary element can be removed without a need to
  210. + * traverse the list. New elements can be added to the list before or after
  211. + * an existing element, at the head of the list, or at the end of the list.
  212. + * A circle queue may be traversed in either direction, but has a more
  213. + * complex end of list detection.
  214. + *
  215. + * For details on the use of these macros, see the queue(3) manual page.
  216. + */
  217. +
  218. +#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
  219. +#define _Q_INVALIDATE(a) (a) = ((void *)-1)
  220. +#else
  221. +#define _Q_INVALIDATE(a)
  222. +#endif
  223. +
  224. +/*
  225. + * Singly-linked List definitions.
  226. + */
  227. +#define SLIST_HEAD(name, type)                                         \
  228. +struct name {                                                          \
  229. +       struct type *slh_first; /* first element */                     \
  230. +}
  231. +
  232. +#define        SLIST_HEAD_INITIALIZER(head)                                   \
  233. +       { NULL }
  234. +
  235. +#define SLIST_ENTRY(type)                                              \
  236. +struct {                                                               \
  237. +       struct type *sle_next;  /* next element */                      \
  238. +}
  239. +
  240. +/*
  241. + * Singly-linked List access methods.
  242. + */
  243. +#define        SLIST_FIRST(head)       ((head)->slh_first)
  244. +#define        SLIST_END(head)         NULL
  245. +#define        SLIST_EMPTY(head)       (SLIST_FIRST(head) == SLIST_END(head))
  246. +#define        SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
  247. +
  248. +#define        SLIST_FOREACH(var, head, field)                                \
  249. +       for((var) = SLIST_FIRST(head);                                  \
  250. +           (var) != SLIST_END(head);                                   \
  251. +           (var) = SLIST_NEXT(var, field))
  252. +
  253. +#define        SLIST_FOREACH_SAFE(var, head, field, tvar)                     \
  254. +       for ((var) = SLIST_FIRST(head);                         \
  255. +           (var) && ((tvar) = SLIST_NEXT(var, field), 1);              \
  256. +           (var) = (tvar))
  257. +
  258. +/*
  259. + * Singly-linked List functions.
  260. + */
  261. +#define        SLIST_INIT(head) {                                             \
  262. +       SLIST_FIRST(head) = SLIST_END(head);                            \
  263. +}
  264. +
  265. +#define        SLIST_INSERT_AFTER(slistelm, elm, field) do {                  \
  266. +       (elm)->field.sle_next = (slistelm)->field.sle_next;             \
  267. +       (slistelm)->field.sle_next = (elm);                             \
  268. +} while (0)
  269. +
  270. +#define        SLIST_INSERT_HEAD(head, elm, field) do {                       \
  271. +       (elm)->field.sle_next = (head)->slh_first;                      \
  272. +       (head)->slh_first = (elm);                                      \
  273. +} while (0)
  274. +
  275. +#define        SLIST_REMOVE_AFTER(elm, field) do {                            \
  276. +       (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next;  \
  277. +} while (0)
  278. +
  279. +#define        SLIST_REMOVE_HEAD(head, field) do {                            \
  280. +       (head)->slh_first = (head)->slh_first->field.sle_next;          \
  281. +} while (0)
  282. +
  283. +#define SLIST_REMOVE(head, elm, type, field) do {                      \
  284. +       if ((head)->slh_first == (elm)) {                               \
  285. +               SLIST_REMOVE_HEAD((head), field);                       \
  286. +       } else {                                                        \
  287. +               struct type *curelm = (head)->slh_first;                \
  288. +                                                                       \
  289. +               while (curelm->field.sle_next != (elm))                 \
  290. +                       curelm = curelm->field.sle_next;                \
  291. +               curelm->field.sle_next =                                \
  292. +                   curelm->field.sle_next->field.sle_next;             \
  293. +               _Q_INVALIDATE((elm)->field.sle_next);                   \
  294. +       }                                                               \
  295. +} while (0)
  296. +
  297. +/*
  298. + * List definitions.
  299. + */
  300. +#define LIST_HEAD(name, type)                                          \
  301. +struct name {                                                          \
  302. +       struct type *lh_first;  /* first element */                     \
  303. +}
  304. +
  305. +#define LIST_HEAD_INITIALIZER(head)                                    \
  306. +       { NULL }
  307. +
  308. +#define LIST_ENTRY(type)                                               \
  309. +struct {                                                               \
  310. +       struct type *le_next;   /* next element */                      \
  311. +       struct type **le_prev;  /* address of previous next element */  \
  312. +}
  313. +
  314. +/*
  315. + * List access methods
  316. + */
  317. +#define        LIST_FIRST(head)                ((head)->lh_first)
  318. +#define        LIST_END(head)                  NULL
  319. +#define        LIST_EMPTY(head)                (LIST_FIRST(head) == LIST_END(head))
  320. +#define        LIST_NEXT(elm, field)           ((elm)->field.le_next)
  321. +
  322. +#define LIST_FOREACH(var, head, field)                                 \
  323. +       for((var) = LIST_FIRST(head);                                   \
  324. +           (var)!= LIST_END(head);                                     \
  325. +           (var) = LIST_NEXT(var, field))
  326. +
  327. +#define        LIST_FOREACH_SAFE(var, head, field, tvar)                      \
  328. +       for ((var) = LIST_FIRST(head);                          \
  329. +           (var) && ((tvar) = LIST_NEXT(var, field), 1);               \
  330. +           (var) = (tvar))
  331. +
  332. +/*
  333. + * List functions.
  334. + */
  335. +#define        LIST_INIT(head) do {                                           \
  336. +       LIST_FIRST(head) = LIST_END(head);                              \
  337. +} while (0)
  338. +
  339. +#define LIST_INSERT_AFTER(listelm, elm, field) do {                    \
  340. +       if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
  341. +               (listelm)->field.le_next->field.le_prev =               \
  342. +                   &(elm)->field.le_next;                              \
  343. +       (listelm)->field.le_next = (elm);                               \
  344. +       (elm)->field.le_prev = &(listelm)->field.le_next;               \
  345. +} while (0)
  346. +
  347. +#define        LIST_INSERT_BEFORE(listelm, elm, field) do {                   \
  348. +       (elm)->field.le_prev = (listelm)->field.le_prev;                \
  349. +       (elm)->field.le_next = (listelm);                               \
  350. +       *(listelm)->field.le_prev = (elm);                              \
  351. +       (listelm)->field.le_prev = &(elm)->field.le_next;               \
  352. +} while (0)
  353. +
  354. +#define LIST_INSERT_HEAD(head, elm, field) do {                               \
  355. +       if (((elm)->field.le_next = (head)->lh_first) != NULL)          \
  356. +               (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
  357. +       (head)->lh_first = (elm);                                       \
  358. +       (elm)->field.le_prev = &(head)->lh_first;                       \
  359. +} while (0)
  360. +
  361. +#define LIST_REMOVE(elm, field) do {                                   \
  362. +       if ((elm)->field.le_next != NULL)                               \
  363. +               (elm)->field.le_next->field.le_prev =                   \
  364. +                   (elm)->field.le_prev;                               \
  365. +       *(elm)->field.le_prev = (elm)->field.le_next;                   \
  366. +       _Q_INVALIDATE((elm)->field.le_prev);                            \
  367. +       _Q_INVALIDATE((elm)->field.le_next);                            \
  368. +} while (0)
  369. +
  370. +#define LIST_REPLACE(elm, elm2, field) do {                            \
  371. +       if (((elm2)->field.le_next = (elm)->field.le_next) != NULL)     \
  372. +               (elm2)->field.le_next->field.le_prev =                  \
  373. +                   &(elm2)->field.le_next;                             \
  374. +       (elm2)->field.le_prev = (elm)->field.le_prev;                   \
  375. +       *(elm2)->field.le_prev = (elm2);                                \
  376. +       _Q_INVALIDATE((elm)->field.le_prev);                            \
  377. +       _Q_INVALIDATE((elm)->field.le_next);                            \
  378. +} while (0)
  379. +
  380. +/*
  381. + * Simple queue definitions.
  382. + */
  383. +#define SIMPLEQ_HEAD(name, type)                                       \
  384. +struct name {                                                          \
  385. +       struct type *sqh_first; /* first element */                     \
  386. +       struct type **sqh_last; /* addr of last next element */         \
  387. +}
  388. +
  389. +#define SIMPLEQ_HEAD_INITIALIZER(head)                                 \
  390. +       { NULL, &(head).sqh_first }
  391. +
  392. +#define SIMPLEQ_ENTRY(type)                                            \
  393. +struct {                                                               \
  394. +       struct type *sqe_next;  /* next element */                      \
  395. +}
  396. +
  397. +/*
  398. + * Simple queue access methods.
  399. + */
  400. +#define        SIMPLEQ_FIRST(head)         ((head)->sqh_first)
  401. +#define        SIMPLEQ_END(head)           NULL
  402. +#define        SIMPLEQ_EMPTY(head)         (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  403. +#define        SIMPLEQ_NEXT(elm, field)    ((elm)->field.sqe_next)
  404. +
  405. +#define SIMPLEQ_FOREACH(var, head, field)                              \
  406. +       for((var) = SIMPLEQ_FIRST(head);                                \
  407. +           (var) != SIMPLEQ_END(head);                                 \
  408. +           (var) = SIMPLEQ_NEXT(var, field))
  409. +
  410. +#define        SIMPLEQ_FOREACH_SAFE(var, head, field, tvar)                   \
  411. +       for ((var) = SIMPLEQ_FIRST(head);                               \
  412. +           (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1);            \
  413. +           (var) = (tvar))
  414. +
  415. +/*
  416. + * Simple queue functions.
  417. + */
  418. +#define        SIMPLEQ_INIT(head) do {                                        \
  419. +       (head)->sqh_first = NULL;                                       \
  420. +       (head)->sqh_last = &(head)->sqh_first;                          \
  421. +} while (0)
  422. +
  423. +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do {                     \
  424. +       if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)        \
  425. +               (head)->sqh_last = &(elm)->field.sqe_next;              \
  426. +       (head)->sqh_first = (elm);                                      \
  427. +} while (0)
  428. +
  429. +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do {                     \
  430. +       (elm)->field.sqe_next = NULL;                                   \
  431. +       *(head)->sqh_last = (elm);                                      \
  432. +       (head)->sqh_last = &(elm)->field.sqe_next;                      \
  433. +} while (0)
  434. +
  435. +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {           \
  436. +       if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  437. +               (head)->sqh_last = &(elm)->field.sqe_next;              \
  438. +       (listelm)->field.sqe_next = (elm);                              \
  439. +} while (0)
  440. +
  441. +#define SIMPLEQ_REMOVE_HEAD(head, field) do {                  \
  442. +       if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  443. +               (head)->sqh_last = &(head)->sqh_first;                  \
  444. +} while (0)
  445. +
  446. +#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do {                    \
  447. +       if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \
  448. +           == NULL)                                                    \
  449. +               (head)->sqh_last = &(elm)->field.sqe_next;              \
  450. +} while (0)
  451. +
  452. +/*
  453. + * Tail queue definitions.
  454. + */
  455. +#define TAILQ_HEAD(name, type)                                         \
  456. +struct name {                                                          \
  457. +       struct type *tqh_first; /* first element */                     \
  458. +       struct type **tqh_last; /* addr of last next element */         \
  459. +}
  460. +
  461. +#define TAILQ_HEAD_INITIALIZER(head)                                   \
  462. +       { NULL, &(head).tqh_first }
  463. +
  464. +#define TAILQ_ENTRY(type)                                              \
  465. +struct {                                                               \
  466. +       struct type *tqe_next;  /* next element */                      \
  467. +       struct type **tqe_prev; /* address of previous next element */  \
  468. +}
  469. +
  470. +/*
  471. + * tail queue access methods
  472. + */
  473. +#define        TAILQ_FIRST(head)               ((head)->tqh_first)
  474. +#define        TAILQ_END(head)                 NULL
  475. +#define        TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
  476. +#define TAILQ_LAST(head, headname)                                     \
  477. +       (*(((struct headname *)((head)->tqh_last))->tqh_last))
  478. +/* XXX */
  479. +#define TAILQ_PREV(elm, headname, field)                               \
  480. +       (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  481. +#define        TAILQ_EMPTY(head)                                              \
  482. +       (TAILQ_FIRST(head) == TAILQ_END(head))
  483. +
  484. +#define TAILQ_FOREACH(var, head, field)                                       \
  485. +       for((var) = TAILQ_FIRST(head);                                  \
  486. +           (var) != TAILQ_END(head);                                   \
  487. +           (var) = TAILQ_NEXT(var, field))
  488. +
  489. +#define        TAILQ_FOREACH_SAFE(var, head, field, tvar)                     \
  490. +       for ((var) = TAILQ_FIRST(head);                                 \
  491. +           (var) != TAILQ_END(head) &&                                 \
  492. +           ((tvar) = TAILQ_NEXT(var, field), 1);                       \
  493. +           (var) = (tvar))
  494. +
  495. +
  496. +#define TAILQ_FOREACH_REVERSE(var, head, headname, field)              \
  497. +       for((var) = TAILQ_LAST(head, headname);                         \
  498. +           (var) != TAILQ_END(head);                                   \
  499. +           (var) = TAILQ_PREV(var, headname, field))
  500. +
  501. +#define        TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)   \
  502. +       for ((var) = TAILQ_LAST(head, headname);                        \
  503. +           (var) != TAILQ_END(head) &&                                 \
  504. +           ((tvar) = TAILQ_PREV(var, headname, field), 1);             \
  505. +           (var) = (tvar))
  506. +
  507. +/*
  508. + * Tail queue functions.
  509. + */
  510. +#define        TAILQ_INIT(head) do {                                          \
  511. +       (head)->tqh_first = NULL;                                       \
  512. +       (head)->tqh_last = &(head)->tqh_first;                          \
  513. +} while (0)
  514. +
  515. +#define TAILQ_INSERT_HEAD(head, elm, field) do {                       \
  516. +       if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)        \
  517. +               (head)->tqh_first->field.tqe_prev =                     \
  518. +                   &(elm)->field.tqe_next;                             \
  519. +       else                                                            \
  520. +               (head)->tqh_last = &(elm)->field.tqe_next;              \
  521. +       (head)->tqh_first = (elm);                                      \
  522. +       (elm)->field.tqe_prev = &(head)->tqh_first;                     \
  523. +} while (0)
  524. +
  525. +#define TAILQ_INSERT_TAIL(head, elm, field) do {                       \
  526. +       (elm)->field.tqe_next = NULL;                                   \
  527. +       (elm)->field.tqe_prev = (head)->tqh_last;                       \
  528. +       *(head)->tqh_last = (elm);                                      \
  529. +       (head)->tqh_last = &(elm)->field.tqe_next;                      \
  530. +} while (0)
  531. +
  532. +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {             \
  533. +       if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  534. +               (elm)->field.tqe_next->field.tqe_prev =                 \
  535. +                   &(elm)->field.tqe_next;                             \
  536. +       else                                                            \
  537. +               (head)->tqh_last = &(elm)->field.tqe_next;              \
  538. +       (listelm)->field.tqe_next = (elm);                              \
  539. +       (elm)->field.tqe_prev = &(listelm)->field.tqe_next;             \
  540. +} while (0)
  541. +
  542. +#define        TAILQ_INSERT_BEFORE(listelm, elm, field) do {                  \
  543. +       (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
  544. +       (elm)->field.tqe_next = (listelm);                              \
  545. +       *(listelm)->field.tqe_prev = (elm);                             \
  546. +       (listelm)->field.tqe_prev = &(elm)->field.tqe_next;             \
  547. +} while (0)
  548. +
  549. +#define TAILQ_REMOVE(head, elm, field) do {                            \
  550. +       if (((elm)->field.tqe_next) != NULL)                            \
  551. +               (elm)->field.tqe_next->field.tqe_prev =                 \
  552. +                   (elm)->field.tqe_prev;                              \
  553. +       else                                                            \
  554. +               (head)->tqh_last = (elm)->field.tqe_prev;               \
  555. +       *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
  556. +       _Q_INVALIDATE((elm)->field.tqe_prev);                           \
  557. +       _Q_INVALIDATE((elm)->field.tqe_next);                           \
  558. +} while (0)
  559. +
  560. +#define TAILQ_REPLACE(head, elm, elm2, field) do {                     \
  561. +       if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL)   \
  562. +               (elm2)->field.tqe_next->field.tqe_prev =                \
  563. +                   &(elm2)->field.tqe_next;                            \
  564. +       else                                                            \
  565. +               (head)->tqh_last = &(elm2)->field.tqe_next;             \
  566. +       (elm2)->field.tqe_prev = (elm)->field.tqe_prev;                 \
  567. +       *(elm2)->field.tqe_prev = (elm2);                               \
  568. +       _Q_INVALIDATE((elm)->field.tqe_prev);                           \
  569. +       _Q_INVALIDATE((elm)->field.tqe_next);                           \
  570. +} while (0)
  571. +
  572. +/*
  573. + * Circular queue definitions.
  574. + */
  575. +#define CIRCLEQ_HEAD(name, type)                                       \
  576. +struct name {                                                          \
  577. +       struct type *cqh_first;         /* first element */             \
  578. +       struct type *cqh_last;          /* last element */              \
  579. +}
  580. +
  581. +#define CIRCLEQ_HEAD_INITIALIZER(head)                                 \
  582. +       { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
  583. +
  584. +#define CIRCLEQ_ENTRY(type)                                            \
  585. +struct {                                                               \
  586. +       struct type *cqe_next;          /* next element */              \
  587. +       struct type *cqe_prev;          /* previous element */          \
  588. +}
  589. +
  590. +/*
  591. + * Circular queue access methods
  592. + */
  593. +#define        CIRCLEQ_FIRST(head)             ((head)->cqh_first)
  594. +#define        CIRCLEQ_LAST(head)              ((head)->cqh_last)
  595. +#define        CIRCLEQ_END(head)               ((void *)(head))
  596. +#define        CIRCLEQ_NEXT(elm, field)        ((elm)->field.cqe_next)
  597. +#define        CIRCLEQ_PREV(elm, field)        ((elm)->field.cqe_prev)
  598. +#define        CIRCLEQ_EMPTY(head)                                            \
  599. +       (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
  600. +
  601. +#define CIRCLEQ_FOREACH(var, head, field)                              \
  602. +       for((var) = CIRCLEQ_FIRST(head);                                \
  603. +           (var) != CIRCLEQ_END(head);                                 \
  604. +           (var) = CIRCLEQ_NEXT(var, field))
  605. +
  606. +#define        CIRCLEQ_FOREACH_SAFE(var, head, field, tvar)                   \
  607. +       for ((var) = CIRCLEQ_FIRST(head);                               \
  608. +           (var) != CIRCLEQ_END(head) &&                               \
  609. +           ((tvar) = CIRCLEQ_NEXT(var, field), 1);                     \
  610. +           (var) = (tvar))
  611. +
  612. +#define CIRCLEQ_FOREACH_REVERSE(var, head, field)                      \
  613. +       for((var) = CIRCLEQ_LAST(head);                                 \
  614. +           (var) != CIRCLEQ_END(head);                                 \
  615. +           (var) = CIRCLEQ_PREV(var, field))
  616. +
  617. +#define        CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
  618. +       for ((var) = CIRCLEQ_LAST(head, headname);                      \
  619. +           (var) != CIRCLEQ_END(head) &&                               \
  620. +           ((tvar) = CIRCLEQ_PREV(var, headname, field), 1);           \
  621. +           (var) = (tvar))
  622. +
  623. +/*
  624. + * Circular queue functions.
  625. + */
  626. +#define        CIRCLEQ_INIT(head) do {                                        \
  627. +       (head)->cqh_first = CIRCLEQ_END(head);                          \
  628. +       (head)->cqh_last = CIRCLEQ_END(head);                           \
  629. +} while (0)
  630. +
  631. +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {           \
  632. +       (elm)->field.cqe_next = (listelm)->field.cqe_next;              \
  633. +       (elm)->field.cqe_prev = (listelm);                              \
  634. +       if ((listelm)->field.cqe_next == CIRCLEQ_END(head))             \
  635. +               (head)->cqh_last = (elm);                               \
  636. +       else                                                            \
  637. +               (listelm)->field.cqe_next->field.cqe_prev = (elm);      \
  638. +       (listelm)->field.cqe_next = (elm);                              \
  639. +} while (0)
  640. +
  641. +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {          \
  642. +       (elm)->field.cqe_next = (listelm);                              \
  643. +       (elm)->field.cqe_prev = (listelm)->field.cqe_prev;              \
  644. +       if ((listelm)->field.cqe_prev == CIRCLEQ_END(head))             \
  645. +               (head)->cqh_first = (elm);                              \
  646. +       else                                                            \
  647. +               (listelm)->field.cqe_prev->field.cqe_next = (elm);      \
  648. +       (listelm)->field.cqe_prev = (elm);                              \
  649. +} while (0)
  650. +
  651. +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do {                     \
  652. +       (elm)->field.cqe_next = (head)->cqh_first;                      \
  653. +       (elm)->field.cqe_prev = CIRCLEQ_END(head);                      \
  654. +       if ((head)->cqh_last == CIRCLEQ_END(head))                      \
  655. +               (head)->cqh_last = (elm);                               \
  656. +       else                                                            \
  657. +               (head)->cqh_first->field.cqe_prev = (elm);              \
  658. +       (head)->cqh_first = (elm);                                      \
  659. +} while (0)
  660. +
  661. +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do {                     \
  662. +       (elm)->field.cqe_next = CIRCLEQ_END(head);                      \
  663. +       (elm)->field.cqe_prev = (head)->cqh_last;                       \
  664. +       if ((head)->cqh_first == CIRCLEQ_END(head))                     \
  665. +               (head)->cqh_first = (elm);                              \
  666. +       else                                                            \
  667. +               (head)->cqh_last->field.cqe_next = (elm);               \
  668. +       (head)->cqh_last = (elm);                                       \
  669. +} while (0)
  670. +
  671. +#define        CIRCLEQ_REMOVE(head, elm, field) do {                          \
  672. +       if ((elm)->field.cqe_next == CIRCLEQ_END(head))                 \
  673. +               (head)->cqh_last = (elm)->field.cqe_prev;               \
  674. +       else                                                            \
  675. +               (elm)->field.cqe_next->field.cqe_prev =                 \
  676. +                   (elm)->field.cqe_prev;                              \
  677. +       if ((elm)->field.cqe_prev == CIRCLEQ_END(head))                 \
  678. +               (head)->cqh_first = (elm)->field.cqe_next;              \
  679. +       else                                                            \
  680. +               (elm)->field.cqe_prev->field.cqe_next =                 \
  681. +                   (elm)->field.cqe_next;                              \
  682. +       _Q_INVALIDATE((elm)->field.cqe_prev);                           \
  683. +       _Q_INVALIDATE((elm)->field.cqe_next);                           \
  684. +} while (0)
  685. +
  686. +#define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                   \
  687. +       if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==         \
  688. +           CIRCLEQ_END(head))                                          \
  689. +               (head).cqh_last = (elm2);                               \
  690. +       else                                                            \
  691. +               (elm2)->field.cqe_next->field.cqe_prev = (elm2);        \
  692. +       if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==         \
  693. +           CIRCLEQ_END(head))                                          \
  694. +               (head).cqh_first = (elm2);                              \
  695. +       else                                                            \
  696. +               (elm2)->field.cqe_prev->field.cqe_next = (elm2);        \
  697. +       _Q_INVALIDATE((elm)->field.cqe_prev);                           \
  698. +       _Q_INVALIDATE((elm)->field.cqe_next);                           \
  699. +} while (0)
  700. +
  701. +#endif /* !_SYS_QUEUE_H_ */
  702. diff -urN ./inadyn-1.99.15/include/tcp.h ./inadyn_padavan/include/tcp.h
  703. --- ./inadyn-1.99.15/include/tcp.h      2016-01-22 13:41:47.000000000 +0300
  704. +++ ./inadyn_padavan/include/tcp.h      2016-01-22 14:22:01.000000000 +0300
  705. @@ -37,7 +37,7 @@
  706.  int tcp_construct          (tcp_sock_t *tcp);
  707.  int tcp_destruct           (tcp_sock_t *tcp);
  708.  
  709. -int tcp_init               (tcp_sock_t *tcp, char *msg);
  710. +int tcp_init               (tcp_sock_t *tcp, char *msg, int verbose);
  711.  int tcp_exit               (tcp_sock_t *tcp);
  712.  
  713.  int tcp_send               (tcp_sock_t *tcp, const char *buf, int len);
  714. diff -urN ./inadyn-1.99.15/Makefile ./inadyn_padavan/Makefile
  715. --- ./inadyn-1.99.15/Makefile   1970-01-01 03:00:00.000000000 +0300
  716. +++ ./inadyn_padavan/Makefile   2016-01-22 14:22:01.000000000 +0300
  717. @@ -0,0 +1,60 @@
  718. +VERSION       = 1.99.15
  719. +NAME          = inadyn
  720. +EXEC          = src/$(NAME)
  721. +RM           ?= rm -f
  722. +SHAREDIR      = $(ROOTDIR)/user/shared
  723. +
  724. +PLUGIN_OBJS   = src/plugin.o           plugins/common.o        \
  725. +               plugins/asuscomm.o      plugins/duckdns.o       \
  726. +               plugins/dyndns.o        plugins/changeip.o      \
  727. +               plugins/dnsexit.o       plugins/easydns.o       \
  728. +               plugins/freedns.o       plugins/generic.o       \
  729. +               plugins/sitelutions.o                           \
  730. +               plugins/tzo.o           plugins/zoneedit.o      \
  731. +               plugins/zerigo.o        plugins/dhis.o          \
  732. +               plugins/dtdns.o         plugins/giradns.o       \
  733. +               plugins/duiadns.o       plugins/netassist.o
  734. +
  735. +BASE_OBJS     = src/main.o     src/ddns.o      src/cache.o     \
  736. +               src/cmd.o       src/os.o        src/error.o     \
  737. +               src/http.o      src/ssl.o       src/tcp.o       \
  738. +               src/ip.o        src/sha1.o      src/base64.o    \
  739. +               src/md5.o
  740. +
  741. +OBJS          = $(BASE_OBJS) $(PLUGIN_OBJS)
  742. +SRCS          = $(OBJS:.o=.c)
  743. +DEPS          = $(SRCS:.c=.d)
  744. +
  745. +CFLAGS       += -W -Wall
  746. +CFLAGS       += -D_BSD_SOURCE -D_GNU_SOURCE
  747. +CFLAGS       += -Iinclude -DVERSION=\"$(VERSION)\"
  748. +CFLAGS       += -Iinclude -I$(SHAREDIR)
  749. +CFLAGS       += -ffunction-sections -fdata-sections
  750. +
  751. +LDFLAGS      += -L$(SHAREDIR) -lshared
  752. +LDFLAGS      += -Wl,--gc-sections
  753. +
  754. +LDLIBS       += -ldl
  755. +
  756. +ifeq ($(CONFIG_FIRMWARE_INCLUDE_DDNS_SSL),y)
  757. +CFLAGS       += -DENABLE_SSL -DCONFIG_OPENSSL
  758. +LDLIBS       += -lssl -lcrypto
  759. +endif
  760. +
  761. +# Pattern rules
  762. +.c.o:
  763. +       $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
  764. +
  765. +# Build rules
  766. +all: $(EXEC)
  767. +
  768. +$(EXEC): $(OBJS)
  769. +       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
  770. +
  771. +clean:
  772. +       -@$(RM) $(OBJS) $(DEPS) $(EXEC)
  773. +
  774. +romfs:
  775. +       $(ROMFSINST) $(EXEC) /bin/inadyn
  776. +
  777. +
  778. diff -urN ./inadyn-1.99.15/plugins/asuscomm.c ./inadyn_padavan/plugins/asuscomm.c
  779. --- ./inadyn-1.99.15/plugins/asuscomm.c 1970-01-01 03:00:00.000000000 +0300
  780. +++ ./inadyn_padavan/plugins/asuscomm.c 2016-01-22 14:22:01.000000000 +0300
  781. @@ -0,0 +1,263 @@
  782. +/* Plugin for asuscomm.com DDNS
  783. + *
  784. + * Copyright (C) 2003-2004  Narcis Ilisei <inarcis2002@hotpop.com>
  785. + * Copyright (C) 2006       Steve Horbachuk
  786. + * Copyright (C) 2010-2014  Joachim Nilsson <troglobit@gmail.com>
  787. + *
  788. + * This program is free software; you can redistribute it and/or
  789. + * modify it under the terms of the GNU General Public License
  790. + * as published by the Free Software Foundation; either version 2
  791. + * of the License, or (at your option) any later version.
  792. + *
  793. + * This program is distributed in the hope that it will be useful,
  794. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  795. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  796. + * GNU General Public License for more details.
  797. + *
  798. + * You should have received a copy of the GNU General Public License
  799. + * along with this program; if not, visit the Free Software Foundation
  800. + * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the
  801. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  802. + * Boston, MA  02110-1301, USA.
  803. + */
  804. +
  805. +#include "md5.h"
  806. +#include "base64.h"
  807. +#include "plugin.h"
  808. +
  809. +#include <ctype.h>
  810. +
  811. +#include <nvram_linux.h>
  812. +
  813. +#define ASUSDDNS_IP_HTTP_REQUEST                                       \
  814. +       "GET %s?"                                                       \
  815. +       "hostname=%s&"                                                  \
  816. +       "myip=%s "                                                      \
  817. +       "HTTP/1.0\r\n"                                                  \
  818. +       "Authorization: Basic %s\r\n"                                   \
  819. +       "Host: %s\r\n"                                                  \
  820. +       "User-Agent: " AGENT_NAME " " SUPPORT_ADDR "\r\n\r\n"
  821. +
  822. +static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias);
  823. +static int response_update(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias);
  824. +static int response_register(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias);
  825. +
  826. +static ddns_system_t asus_update = {
  827. +       .name         = "update@asus.com",
  828. +
  829. +       .request      = (req_fn_t)request,
  830. +       .response     = (rsp_fn_t)response_update,
  831. +
  832. +       .checkip_name = DYNDNS_MY_IP_SERVER,
  833. +       .checkip_url  = DYNDNS_MY_CHECKIP_URL,
  834. +
  835. +       .server_name  = "ns1.asuscomm.com",
  836. +       .server_url   = "/ddns/update.jsp"
  837. +};
  838. +
  839. +static ddns_system_t asus_register = {
  840. +       .name         = "register@asus.com",
  841. +
  842. +       .request      = (req_fn_t)request,
  843. +       .response     = (rsp_fn_t)response_register,
  844. +
  845. +       .checkip_name = DYNDNS_MY_IP_SERVER,
  846. +       .checkip_url  = DYNDNS_MY_CHECKIP_URL,
  847. +
  848. +       .server_name  = "ns1.asuscomm.com",
  849. +       .server_url   = "/ddns/register.jsp"
  850. +};
  851. +
  852. +#define MD5_DIGEST_BYTES 16
  853. +static void
  854. +hmac_md5( const unsigned char *input, size_t ilen, const unsigned char *key, size_t klen, unsigned char output[MD5_DIGEST_BYTES] )
  855. +{
  856. +       int i;
  857. +       md5_context ctx;
  858. +       unsigned char k_ipad[64], k_opad[64], tk[MD5_DIGEST_BYTES];
  859. +
  860. +       /* if key is longer than 64 bytes reset it to key=MD5(key) */
  861. +       if (klen > 64) {
  862. +               md5(key, klen, tk);
  863. +               key = tk;
  864. +               klen = MD5_DIGEST_BYTES;
  865. +       }
  866. +
  867. +       /* start out by storing key in pads */
  868. +       memset(k_ipad, 0, sizeof(k_ipad));
  869. +       memset(k_opad, 0, sizeof(k_opad));
  870. +       memcpy(k_ipad, key, klen);
  871. +       memcpy(k_opad, key, klen);
  872. +
  873. +       /*xor key with ipad and opad values */
  874. +       for (i = 0; i < 64; i++) {
  875. +               k_ipad[i] ^= 0x36;
  876. +               k_opad[i] ^= 0x5c;
  877. +       }
  878. +
  879. +       /* inner MD5 */
  880. +       md5_starts( &ctx );
  881. +       md5_update( &ctx, k_ipad, 64 );
  882. +       md5_update( &ctx, input, ilen );
  883. +       md5_finish( &ctx, output );
  884. +
  885. +       /* outter MD5 */
  886. +       md5_starts( &ctx );
  887. +       md5_update( &ctx, k_opad, 64 );
  888. +       md5_update( &ctx, output, MD5_DIGEST_BYTES );
  889. +       md5_finish( &ctx, output );
  890. +
  891. +       memset( &ctx, 0, sizeof( md5_context ) );
  892. +}
  893. +
  894. +static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
  895. +{
  896. +       unsigned char digest[MD5_DIGEST_BYTES];
  897. +       char auth[6*2+1+MD5_DIGEST_BYTES*2+1];
  898. +       char *p_tmp, *p_auth = auth;
  899. +       char *p_b64_buff = NULL;
  900. +       size_t dlen = 0;
  901. +       int i;
  902. +
  903. +       /* prepare username (MAC) */
  904. +       p_tmp = info->creds.username;
  905. +       for (i = 0; i < 6*2; i++) {
  906. +               while (*p_tmp && !isxdigit(*p_tmp))
  907. +                       p_tmp++;
  908. +               *p_auth++ = *p_tmp ? toupper(*p_tmp++) : '0';
  909. +       }
  910. +
  911. +       /* split username and password */
  912. +       *p_auth++ = ':';
  913. +
  914. +       /* prepare password, reuse request_buf */
  915. +       snprintf(ctx->request_buf, ctx->request_buflen, "%s%s",
  916. +               alias->name,
  917. +               alias->address);
  918. +       hmac_md5(ctx->request_buf, strlen(ctx->request_buf),
  919. +               info->creds.password, strlen(info->creds.password), digest);
  920. +       for (i = 0; i < MD5_DIGEST_BYTES; i++)
  921. +               p_auth += sprintf(p_auth, "%02X", digest[i]);
  922. +
  923. +       /*encode*/
  924. +       base64_encode(NULL, &dlen, auth, strlen(auth));
  925. +       p_b64_buff = (char *) malloc(dlen);
  926. +       if (p_b64_buff)
  927. +               base64_encode(p_b64_buff, &dlen, auth, strlen(auth));
  928. +
  929. +       if (info->creds.encoded_password)
  930. +               free(info->creds.encoded_password);
  931. +
  932. +       info->creds.encoded_password = p_b64_buff;
  933. +       info->creds.encoded = (p_b64_buff != NULL) ? 1 : 0;
  934. +       info->creds.size = strlen(info->creds.encoded_password);
  935. +
  936. +       return snprintf(ctx->request_buf, ctx->request_buflen,
  937. +                       ASUSDDNS_IP_HTTP_REQUEST,
  938. +                       info->server_url,
  939. +                       alias->name,
  940. +                       alias->address,
  941. +                       info->creds.encoded_password,
  942. +                       info->server_name.name);
  943. +}
  944. +
  945. +static int response_update(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
  946. +{
  947. +       char *p, *p_rsp;
  948. +       char domain[256] = {0};
  949. +
  950. +       p_rsp = trans->p_rsp_body;
  951. +
  952. +       if ((p = strchr(p_rsp, '|')) && (p = strchr(++p, '|')))
  953. +               sscanf(p, "|%255[^|\r\n]", domain);
  954. +
  955. +       switch (trans->status) {
  956. +               case 200:               /* update success */
  957. +               case 220:               /* update same domain success -- unused?? */
  958. +                       return RC_OK;
  959. +               case 203:               /* update failed */
  960. +                       logit(LOG_WARNING, "Domain already in use, suggested domain '%s'", domain);
  961. +                       return RC_DYNDNS_RSP_NOTOK;
  962. +               case 233:               /* update failed */
  963. +                       logit(LOG_WARNING, "Domain already in use, current domain '%s'", domain);
  964. +                       return RC_DYNDNS_RSP_NOTOK;
  965. +               case 297:               /* invalid hostname */
  966. +               case 298:               /* invalid domain name */
  967. +               case 299:               /* invalid ip format */
  968. +               case 401:               /* authentication failure */
  969. +               case 407:               /* proxy authentication required */
  970. +                       return RC_DYNDNS_RSP_NOTOK;
  971. +       }
  972. +
  973. +       if (trans->status >= 500 && trans->status < 600)
  974. +               return RC_DYNDNS_RSP_RETRY_LATER;
  975. +
  976. +       return RC_DYNDNS_RSP_NOTOK;
  977. +}
  978. +
  979. +static int response_register(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
  980. +{
  981. +       char *p, *p_rsp, *ret_key;
  982. +       char ret_buf[64], domain[256] = {0};
  983. +
  984. +       ret_key = "ddns_return_code";
  985. +
  986. +       p_rsp = trans->p_rsp_body;
  987. +
  988. +       if ((p = strchr(p_rsp, '|')) && (p = strchr(++p, '|')))
  989. +               sscanf(p, "|%255[^|\r\n]", domain);
  990. +
  991. +       if (trans->status >= 500 && trans->status < 600) {
  992. +               nvram_set_temp(ret_key, "unknown_error");
  993. +               return RC_DYNDNS_RSP_RETRY_LATER;
  994. +       }
  995. +
  996. +       snprintf(ret_buf, sizeof(ret_buf), "%s,%d", "register", trans->status);
  997. +       nvram_set_temp(ret_key, ret_buf);
  998. +
  999. +       switch (trans->status) {
  1000. +       case 200:               /* registration success */
  1001. +       case 220:               /* registration same domain success*/
  1002. +               return RC_OK;
  1003. +       case 203:               /* registration failed */
  1004. +               logit(LOG_WARNING, "Domain already in use, suggested domain '%s'", domain);
  1005. +               return RC_DYNDNS_RSP_NOTOK;
  1006. +       case 230:               /* registration new domain success */
  1007. +               logit(LOG_WARNING, "Registration success, previous domain '%s'", domain);
  1008. +               return RC_OK;
  1009. +       case 233:               /* registration failed */
  1010. +               logit(LOG_WARNING, "Domain already in use, current domain '%s'", domain);
  1011. +               return RC_DYNDNS_RSP_NOTOK;
  1012. +       case 297:               /* invalid hostname */
  1013. +       case 298:               /* invalid domain name */
  1014. +       case 299:               /* invalid ip format */
  1015. +       case 401:               /* authentication failure */
  1016. +       case 407:               /* proxy authentication required */
  1017. +               return RC_DYNDNS_RSP_NOTOK;
  1018. +       }
  1019. +
  1020. +       if (trans->status < 500)                /* shutdown */
  1021. +               nvram_set_temp(ret_key, "time_out");
  1022. +
  1023. +       return RC_DYNDNS_RSP_NOTOK;
  1024. +}
  1025. +
  1026. +PLUGIN_INIT(plugin_init)
  1027. +{
  1028. +       plugin_register(&asus_update);
  1029. +       plugin_register(&asus_register);
  1030. +}
  1031. +
  1032. +PLUGIN_EXIT(plugin_exit)
  1033. +{
  1034. +       plugin_unregister(&asus_update);
  1035. +       plugin_unregister(&asus_register);
  1036. +}
  1037. +
  1038. +/**
  1039. + * Local Variables:
  1040. + *  version-control: t
  1041. + *  indent-tabs-mode: t
  1042. + *  c-file-style: "linux"
  1043. + * End:
  1044. + */
  1045. diff -urN ./inadyn-1.99.15/plugins/common.c ./inadyn_padavan/plugins/common.c
  1046. --- ./inadyn-1.99.15/plugins/common.c   2016-01-22 13:41:47.000000000 +0300
  1047. +++ ./inadyn_padavan/plugins/common.c   2016-01-22 14:22:01.000000000 +0300
  1048. @@ -47,7 +47,7 @@
  1049.         char wildcard[20] = "";
  1050.  
  1051.         if (info->wildcard)
  1052. -               strlcpy(wildcard, "&wildcard=ON", sizeof(wildcard));
  1053. +               strcpy(wildcard, "&wildcard=ON");
  1054.  
  1055.         return snprintf(ctx->request_buf, ctx->request_buflen,
  1056.                         DYNDNS_UPDATE_IP_HTTP_REQUEST,
  1057. @@ -70,7 +70,7 @@
  1058.         DO(http_status_valid(trans->status));
  1059.  
  1060.         if (strstr(body, "good") != NULL || strstr(body, "nochg"))
  1061. -               return 0;
  1062. +               return RC_OK;
  1063.  
  1064.         if (strstr(body, "dnserr") != NULL || strstr(body, "911"))
  1065.                 return RC_DYNDNS_RSP_RETRY_LATER;
  1066. diff -urN ./inadyn-1.99.15/plugins/dhis.c ./inadyn_padavan/plugins/dhis.c
  1067. --- ./inadyn-1.99.15/plugins/dhis.c     2016-01-22 13:41:48.000000000 +0300
  1068. +++ ./inadyn_padavan/plugins/dhis.c     2016-01-22 14:22:01.000000000 +0300
  1069. @@ -67,7 +67,7 @@
  1070.         DO(http_status_valid(trans->status));
  1071.  
  1072.         if (strstr(rsp, alias->address))
  1073. -               return 0;
  1074. +               return RC_OK;
  1075.  
  1076.         return RC_DYNDNS_RSP_NOTOK;
  1077.  }
  1078. diff -urN ./inadyn-1.99.15/plugins/dnsexit.c ./inadyn_padavan/plugins/dnsexit.c
  1079. --- ./inadyn-1.99.15/plugins/dnsexit.c  2016-01-22 13:41:47.000000000 +0300
  1080. +++ ./inadyn_padavan/plugins/dnsexit.c  2016-01-22 14:22:01.000000000 +0300
  1081. @@ -75,8 +75,8 @@
  1082.         switch (code) {
  1083.         case 0:
  1084.         case 1:
  1085. -               return 0;
  1086.         case 4:
  1087. +               return RC_OK;
  1088.         case 11:
  1089.                 return RC_DYNDNS_RSP_RETRY_LATER;
  1090.         default:
  1091. diff -urN ./inadyn-1.99.15/plugins/duckdns.c ./inadyn_padavan/plugins/duckdns.c
  1092. --- ./inadyn-1.99.15/plugins/duckdns.c  2016-01-22 13:41:48.000000000 +0300
  1093. +++ ./inadyn_padavan/plugins/duckdns.c  2016-01-22 14:22:01.000000000 +0300
  1094. @@ -22,11 +22,15 @@
  1095.  
  1096.  #include "plugin.h"
  1097.  
  1098. +/*
  1099. + * For API documentation we currently only have this
  1100. + *     https://www.duckdns.org/install.jsp#linux-cron
  1101. + */
  1102.  #define DUCKDNS_UPDATE_IP_HTTP_REQUEST                                 \
  1103.         "GET %s?"                                                       \
  1104.         "domains=%s&"                                                   \
  1105.         "token=%s&"                                                     \
  1106. -       "ip=%s& "                                                       \
  1107. +       "ip=%s "                                                        \
  1108.         "HTTP/1.0\r\n"                                                  \
  1109.         "Host: %s\r\n"                                                  \
  1110.         "User-Agent: " AGENT_NAME " " SUPPORT_ADDR "\r\n\r\n"
  1111. @@ -43,31 +47,29 @@
  1112.         .checkip_name = "ipv4.wtfismyip.com",
  1113.         .checkip_url  = "/text",
  1114.  
  1115. -       .server_name  = "duckdns.org",
  1116. +       .server_name  = "www.duckdns.org",
  1117.         .server_url   = "/update"
  1118.  };
  1119.  
  1120.  static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
  1121.  {
  1122. -       char name[SERVER_NAME_LEN], *p;
  1123. +       char h_name[SERVER_NAME_LEN], *p;
  1124.  
  1125. -       /* Handle some.name.duckdns.org properly */
  1126.         p = strstr(alias->name, "duckdns.org");
  1127. -       if (p) {
  1128. -               size_t len = p - alias->name;
  1129. -
  1130. -               if (len > sizeof(name))
  1131. -                       len = sizeof(name);
  1132. -
  1133. -               strlcpy(name, alias->name, len);
  1134. +       if ((p != NULL) && (p != alias->name) && (*(--p) == '.')) {
  1135. +               size_t h_len = (size_t)(p - alias->name);
  1136. +               if (h_len >= sizeof(h_name))
  1137. +                       h_len = sizeof(h_name) - 1;
  1138. +               strncpy(h_name, alias->name, h_len);
  1139. +               h_name[h_len] = '\0';
  1140.         } else {
  1141. -               snprintf(name, sizeof(name), "%s", alias->name);
  1142. +               snprintf(h_name, sizeof(h_name), "%s", alias->name);
  1143.         }
  1144.  
  1145.         return snprintf(ctx->request_buf, ctx->request_buflen,
  1146.                         DUCKDNS_UPDATE_IP_HTTP_REQUEST,
  1147.                         info->server_url,
  1148. -                       name,
  1149. +                       h_name,
  1150.                         info->creds.username,
  1151.                         alias->address,
  1152.                         info->server_name.name);
  1153. @@ -79,7 +81,7 @@
  1154.  
  1155.         DO(http_status_valid(trans->status));
  1156.  
  1157. -       if (strstr(resp, "KO") || strstr(resp, "OK") || strstr(resp, "good"))
  1158. +       if (strstr(resp, "OK") || strstr(resp, "good"))
  1159.                 return RC_OK;
  1160.  
  1161.         return RC_DYNDNS_RSP_NOTOK;
  1162. diff -urN ./inadyn-1.99.15/plugins/dyndns.c ./inadyn_padavan/plugins/dyndns.c
  1163. --- ./inadyn-1.99.15/plugins/dyndns.c   2016-01-22 13:41:47.000000000 +0300
  1164. +++ ./inadyn_padavan/plugins/dyndns.c   2016-01-22 14:22:01.000000000 +0300
  1165. @@ -10,6 +10,7 @@
  1166.   *   - Loopia, and
  1167.   *   - nsupdate.info
  1168.   *   - Google Domains
  1169. + *   - nic.ru (RU-CENTER)
  1170.   *
  1171.   * Copyright (C) 2003-2004  Narcis Ilisei <inarcis2002@hotpop.com>
  1172.   * Copyright (C) 2006       Steve Horbachuk
  1173. @@ -179,6 +180,23 @@
  1174.         .server_url   = "/nic/update"
  1175.  };
  1176.  
  1177. +/*
  1178. + * nic.ru (RU-CENTER)
  1179. + * https://www.nic.ru/dns/service/dns_hosting/dns_master/dynamic_dns_for_developers.html
  1180. + */
  1181. +static ddns_system_t nic_ru = {
  1182. +       .name         = "default@nic.ru",
  1183. +
  1184. +       .request      = (req_fn_t)request,
  1185. +       .response     = (rsp_fn_t)response,
  1186. +
  1187. +       .checkip_name = "api.nic.ru:443",
  1188. +       .checkip_url  = "/dyndns/checkip",
  1189. +
  1190. +       .server_name  = "api.nic.ru:443",
  1191. +       .server_url   = "/dyndns/update"
  1192. +};
  1193. +
  1194.  static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
  1195.  {
  1196.         return common_request(ctx, info, alias);
  1197. @@ -201,6 +219,7 @@
  1198.         plugin_register(&nsupdate_info_ipv4);
  1199.         plugin_register(&loopia);
  1200.         plugin_register(&googledomains);
  1201. +       plugin_register(&nic_ru);
  1202.  }
  1203.  
  1204.  PLUGIN_EXIT(plugin_exit)
  1205. @@ -215,6 +234,7 @@
  1206.         plugin_unregister(&nsupdate_info_ipv4);
  1207.         plugin_unregister(&loopia);
  1208.         plugin_unregister(&googledomains);
  1209. +       plugin_unregister(&nic_ru);
  1210.  }
  1211.  
  1212.  /**
  1213. diff -urN ./inadyn-1.99.15/plugins/easydns.c ./inadyn_padavan/plugins/easydns.c
  1214. --- ./inadyn-1.99.15/plugins/easydns.c  2016-01-22 13:41:47.000000000 +0300
  1215. +++ ./inadyn_padavan/plugins/easydns.c  2016-01-22 14:22:01.000000000 +0300
  1216. @@ -75,7 +75,7 @@
  1217.         DO(http_status_valid(trans->status));
  1218.  
  1219.         if (strstr(resp, "NOERROR"))
  1220. -               return 0;
  1221. +               return RC_OK;
  1222.  
  1223.         if (strstr(resp, "TOOSOON"))
  1224.                 return RC_DYNDNS_RSP_RETRY_LATER;
  1225. diff -urN ./inadyn-1.99.15/plugins/freedns.c ./inadyn_padavan/plugins/freedns.c
  1226. --- ./inadyn-1.99.15/plugins/freedns.c  2016-01-22 13:41:47.000000000 +0300
  1227. +++ ./inadyn_padavan/plugins/freedns.c  2016-01-22 14:22:01.000000000 +0300
  1228. @@ -68,9 +68,8 @@
  1229.                 http_set_remote_name(&client, info->server_name.name);
  1230.                 http_set_bind_iface(&client, ctx->bind_interface);
  1231.  
  1232. +               client.verbose = ctx->dbg.level;
  1233.                 client.ssl_enabled = info->ssl_enabled;
  1234. -               if (client.ssl_enabled) /* XXX: Fix this better, possibly in http_init() */
  1235. -                       client.tcp.ip.port = 443;
  1236.  
  1237.                 TRY(http_init(&client, "Sending update URL query"));
  1238.  
  1239. @@ -118,7 +117,7 @@
  1240.  
  1241.         if (rc) {
  1242.                 logit(LOG_INFO, "Update URL query failed");
  1243. -               return 0;
  1244. +               return RC_OK;
  1245.         }
  1246.  
  1247.         return snprintf(ctx->request_buf, ctx->request_buflen,
  1248. @@ -140,7 +139,7 @@
  1249.         DO(http_status_valid(trans->status));
  1250.  
  1251.         if (strstr(resp, alias->address))
  1252. -               return 0;
  1253. +               return RC_OK;
  1254.  
  1255.         return RC_DYNDNS_RSP_NOTOK;
  1256.  }
  1257. diff -urN ./inadyn-1.99.15/plugins/generic.c ./inadyn_padavan/plugins/generic.c
  1258. --- ./inadyn-1.99.15/plugins/generic.c  2016-01-22 13:41:48.000000000 +0300
  1259. +++ ./inadyn_padavan/plugins/generic.c  2016-01-22 14:22:01.000000000 +0300
  1260. @@ -95,7 +95,7 @@
  1261.         DO(http_status_valid(trans->status));
  1262.  
  1263.         if (strstr(resp, "OK") || strstr(resp, "good") || strstr(resp, "true"))
  1264. -               return 0;
  1265. +               return RC_OK;
  1266.  
  1267.         return RC_DYNDNS_RSP_NOTOK;
  1268.  }
  1269. diff -urN ./inadyn-1.99.15/plugins/netassist.c ./inadyn_padavan/plugins/netassist.c
  1270. --- ./inadyn-1.99.15/plugins/netassist.c        1970-01-01 03:00:00.000000000 +0300
  1271. +++ ./inadyn_padavan/plugins/netassist.c        2016-01-22 14:22:01.000000000 +0300
  1272. @@ -0,0 +1,96 @@
  1273. +/* Plugin for tb.netassist.ua IPV6 tunnelbroker
  1274. + *
  1275. + * Copyright (C) 2003-2004  Narcis Ilisei <inarcis2002@hotpop.com>
  1276. + * Copyright (C) 2006       Steve Horbachuk
  1277. + * Copyright (C) 2010-2014  Joachim Nilsson <troglobit@gmail.com>
  1278. + *
  1279. + * This program is free software; you can redistribute it and/or
  1280. + * modify it under the terms of the GNU General Public License
  1281. + * as published by the Free Software Foundation; either version 2
  1282. + * of the License, or (at your option) any later version.
  1283. + *
  1284. + * This program is distributed in the hope that it will be useful,
  1285. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1286. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1287. + * GNU General Public License for more details.
  1288. + *
  1289. + * You should have received a copy of the GNU General Public License
  1290. + * along with this program; if not, visit the Free Software Foundation
  1291. + * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the
  1292. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  1293. + * Boston, MA  02110-1301, USA.
  1294. + */
  1295. +
  1296. +#include "plugin.h"
  1297. +
  1298. +/* tb.netassist.ua specific update request format */
  1299. +#define NETASSIST_IPV6TB_UPDATE_IP_REQUEST                                    \
  1300. +       "GET %s?"                                                       \
  1301. +       "l=%s&"                                                 \
  1302. +       "p=%s&"                                                 \
  1303. +       "ip=%s "                                                        \
  1304. +       "HTTP/1.0\r\n"                                                  \
  1305. +       "Host: %s\r\n"                                                  \
  1306. +       "User-Agent: " AGENT_NAME " " SUPPORT_ADDR "\r\n\r\n"
  1307. +
  1308. +static int request  (ddns_t       *ctx,   ddns_info_t *info, ddns_alias_t *alias);
  1309. +static int response (http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias);
  1310. +
  1311. +static ddns_system_t plugin = {
  1312. +       .name         = "ipv6tb@netassist.ua",
  1313. +
  1314. +       .request      = (req_fn_t)request,
  1315. +       .response     = (rsp_fn_t)response,
  1316. +
  1317. +       .checkip_name = "ipv4.wtfismyip.com",
  1318. +       .checkip_url  = "/text",
  1319. +
  1320. +       .server_name  = "tb.netassist.ua",
  1321. +       .server_url   = "/autochangeip.php"
  1322. +};
  1323. +
  1324. +static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
  1325. +{
  1326. +       return snprintf(ctx->request_buf, ctx->request_buflen,
  1327. +                       NETASSIST_IPV6TB_UPDATE_IP_REQUEST,
  1328. +                       info->server_url,
  1329. +                       info->creds.username,
  1330. +                       info->creds.password,
  1331. +                       alias->address,
  1332. +                       info->server_name.name);
  1333. +}
  1334. +
  1335. +/*
  1336. + * tb.netassist.ua specific response validation
  1337. + * 'OK!' and 'is already registered' are the good answers.
  1338. + */
  1339. +static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
  1340. +{
  1341. +       char *resp = trans->p_rsp_body;
  1342. +
  1343. +       DO(http_status_valid(trans->status));
  1344. +
  1345. +       if (strstr(resp, "OK!") ||
  1346. +           strstr(resp, "already"))
  1347. +               return RC_OK;
  1348. +
  1349. +       return RC_DYNDNS_RSP_NOTOK;
  1350. +}
  1351. +
  1352. +PLUGIN_INIT(plugin_init)
  1353. +{
  1354. +       plugin_register(&plugin);
  1355. +}
  1356. +
  1357. +PLUGIN_EXIT(plugin_exit)
  1358. +{
  1359. +       plugin_unregister(&plugin);
  1360. +}
  1361. +
  1362. +/**
  1363. + * Local Variables:
  1364. + *  version-control: t
  1365. + *  indent-tabs-mode: t
  1366. + *  c-file-style: "linux"
  1367. + * End:
  1368. + */
  1369. diff -urN ./inadyn-1.99.15/plugins/sitelutions.c ./inadyn_padavan/plugins/sitelutions.c
  1370. --- ./inadyn-1.99.15/plugins/sitelutions.c      2016-01-22 13:41:47.000000000 +0300
  1371. +++ ./inadyn_padavan/plugins/sitelutions.c      2016-01-22 14:22:01.000000000 +0300
  1372. @@ -69,7 +69,7 @@
  1373.         DO(http_status_valid(trans->status));
  1374.  
  1375.         if (strstr(resp, "success"))
  1376. -               return 0;
  1377. +               return RC_OK;
  1378.  
  1379.         if (strstr(resp, "dberror"))
  1380.                 return RC_DYNDNS_RSP_RETRY_LATER;
  1381. diff -urN ./inadyn-1.99.15/plugins/tunnelbroker.c.deprecated ./inadyn_padavan/plugins/tunnelbroker.c.deprecated
  1382. --- ./inadyn-1.99.15/plugins/tunnelbroker.c.deprecated  1970-01-01 03:00:00.000000000 +0300
  1383. +++ ./inadyn_padavan/plugins/tunnelbroker.c.deprecated  2016-01-22 14:22:01.000000000 +0300
  1384. @@ -0,0 +1,99 @@
  1385. +/* Plugin for Hurricate Electric's IPv6 service
  1386. + *
  1387. + * Copyright (C) 2003-2004  Narcis Ilisei <inarcis2002@hotpop.com>
  1388. + * Copyright (C) 2006       Steve Horbachuk
  1389. + * Copyright (C) 2010-2014  Joachim Nilsson <troglobit@gmail.com>
  1390. + *
  1391. + * This program is free software; you can redistribute it and/or
  1392. + * modify it under the terms of the GNU General Public License
  1393. + * as published by the Free Software Foundation; either version 2
  1394. + * of the License, or (at your option) any later version.
  1395. + *
  1396. + * This program is distributed in the hope that it will be useful,
  1397. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1398. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1399. + * GNU General Public License for more details.
  1400. + *
  1401. + * You should have received a copy of the GNU General Public License
  1402. + * along with this program; if not, visit the Free Software Foundation
  1403. + * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the
  1404. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  1405. + * Boston, MA  02110-1301, USA.
  1406. + */
  1407. +
  1408. +#include "plugin.h"
  1409. +
  1410. +/* HE tunnelbroker.com specific update request format */
  1411. +#define HE_IPV6TB_UPDATE_IP_REQUEST                                    \
  1412. +       "GET %s?"                                                       \
  1413. +       "username=%s&"                                                  \
  1414. +       "password=%s&"                                                  \
  1415. +       "hostname=%s&"                                                  \
  1416. +       "myip=%s "                                                      \
  1417. +       "HTTP/1.0\r\n"                                                  \
  1418. +       "Host: %s\r\n"                                                  \
  1419. +       "User-Agent: " AGENT_NAME " " SUPPORT_ADDR "\r\n\r\n"
  1420. +
  1421. +static int request  (ddns_t       *ctx,   ddns_info_t *info, ddns_alias_t *alias);
  1422. +static int response (http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias);
  1423. +
  1424. +static ddns_system_t plugin = {
  1425. +       .name         = "ipv6tb@he.net",
  1426. +
  1427. +       .request      = (req_fn_t)request,
  1428. +       .response     = (rsp_fn_t)response,
  1429. +
  1430. +       .checkip_name = "checkip.dns.he.net",
  1431. +       .checkip_url  = "/",
  1432. +
  1433. +       .server_name  = "ipv4.tunnelbroker.net",
  1434. +       .server_url   = "/nic/update"
  1435. +};
  1436. +
  1437. +static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
  1438. +{
  1439. +       return snprintf(ctx->request_buf, ctx->request_buflen,
  1440. +                       HE_IPV6TB_UPDATE_IP_REQUEST,
  1441. +                       info->server_url,
  1442. +                       info->creds.username,
  1443. +                       info->creds.password,
  1444. +                       alias->name,
  1445. +                       alias->address,
  1446. +                       info->server_name.name);
  1447. +}
  1448. +
  1449. +/*
  1450. + * Hurricate Electric IPv6 tunnelbroker specific response validator
  1451. + * Own IP address and 'already in use' are the good answers.
  1452. + */
  1453. +static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *alias)
  1454. +{
  1455. +       char *resp = trans->p_rsp_body;
  1456. +
  1457. +       DO(http_status_valid(trans->status));
  1458. +
  1459. +       if (strstr(resp, alias->address) ||
  1460. +           strstr(resp, "already"))
  1461. +//         strstr(resp, "-ERROR: This tunnel is already associated with this IP address."))
  1462. +               return RC_OK;
  1463. +
  1464. +       return RC_DYNDNS_RSP_NOTOK;
  1465. +}
  1466. +
  1467. +PLUGIN_INIT(plugin_init)
  1468. +{
  1469. +       plugin_register(&plugin);
  1470. +}
  1471. +
  1472. +PLUGIN_EXIT(plugin_exit)
  1473. +{
  1474. +       plugin_unregister(&plugin);
  1475. +}
  1476. +
  1477. +/**
  1478. + * Local Variables:
  1479. + *  version-control: t
  1480. + *  indent-tabs-mode: t
  1481. + *  c-file-style: "linux"
  1482. + * End:
  1483. + */
  1484. diff -urN ./inadyn-1.99.15/plugins/tzo.c ./inadyn_padavan/plugins/tzo.c
  1485. --- ./inadyn-1.99.15/plugins/tzo.c      2016-01-22 13:41:47.000000000 +0300
  1486. +++ ./inadyn_padavan/plugins/tzo.c      2016-01-22 14:22:01.000000000 +0300
  1487. @@ -75,7 +75,7 @@
  1488.         switch (code) {
  1489.         case 200:
  1490.         case 304:
  1491. -               return 0;
  1492. +               return RC_OK;
  1493.         case 414:
  1494.         case 500:
  1495.                 return RC_DYNDNS_RSP_RETRY_LATER;
  1496. diff -urN ./inadyn-1.99.15/plugins/zerigo.c ./inadyn_padavan/plugins/zerigo.c
  1497. --- ./inadyn-1.99.15/plugins/zerigo.c   2016-01-22 13:41:47.000000000 +0300
  1498. +++ ./inadyn_padavan/plugins/zerigo.c   2016-01-22 14:22:01.000000000 +0300
  1499. @@ -84,7 +84,7 @@
  1500.  
  1501.                 switch (code) {
  1502.                 case 2:
  1503. -                       return 0;
  1504. +                       return RC_OK;
  1505.  
  1506.                 case 4:
  1507.                         return RC_DYNDNS_INVALID_OR_MISSING_PARAMETERS;
  1508. diff -urN ./inadyn-1.99.15/plugins/zoneedit.c ./inadyn_padavan/plugins/zoneedit.c
  1509. --- ./inadyn-1.99.15/plugins/zoneedit.c 2016-01-22 13:41:47.000000000 +0300
  1510. +++ ./inadyn_padavan/plugins/zoneedit.c 2016-01-22 14:22:01.000000000 +0300
  1511. @@ -76,7 +76,7 @@
  1512.         case 201:
  1513.         case 707:
  1514.                 /* XXX: is 707 really OK? */
  1515. -               return 0;
  1516. +               return RC_OK;
  1517.         default:
  1518.                 break;
  1519.         }
  1520. diff -urN ./inadyn-1.99.15/src/base64.c ./inadyn_padavan/src/base64.c
  1521. --- ./inadyn-1.99.15/src/base64.c       2016-01-22 13:41:47.000000000 +0300
  1522. +++ ./inadyn_padavan/src/base64.c       2016-01-22 14:22:01.000000000 +0300
  1523. @@ -1,26 +1,27 @@
  1524. -/*
  1525. - *  RFC 1521 base64 encoding/decoding
  1526. - *
  1527. - *  Copyright (C) 2006-2013, Brainspark B.V.
  1528. +/* RFC 1521 base64 encoding/decoding
  1529.   *
  1530. - *  This file is part of PolarSSL (http://www.polarssl.org)
  1531. - *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  1532. + * Copyright (C) 2006-2010, Brainspark B.V.
  1533.   *
  1534. - *  All rights reserved.
  1535. + * This file is part of PolarSSL (http://www.polarssl.org)
  1536. + * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  1537.   *
  1538. - *  This program is free software; you can redistribute it and/or modify
  1539. - *  it under the terms of the GNU General Public License as published by
  1540. - *  the Free Software Foundation; either version 2 of the License, or
  1541. - *  (at your option) any later version.
  1542. + * All rights reserved.
  1543.   *
  1544. - *  This program is distributed in the hope that it will be useful,
  1545. - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  1546. - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1547. - *  GNU General Public License for more details.
  1548. - *
  1549. - *  You should have received a copy of the GNU General Public License along
  1550. - *  with this program; if not, write to the Free Software Foundation, Inc.,
  1551. - *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  1552. + * This program is free software; you can redistribute it and/or
  1553. + * modify it under the terms of the GNU General Public License
  1554. + * as published by the Free Software Foundation; either version 2
  1555. + * of the License, or (at your option) any later version.
  1556. + *
  1557. + * This program is distributed in the hope that it will be useful,
  1558. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1559. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1560. + * GNU General Public License for more details.
  1561. + *
  1562. + * You should have received a copy of the GNU General Public License
  1563. + * along with this program; if not, visit the Free Software Foundation
  1564. + * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the
  1565. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  1566. + * Boston, MA 02110-1301, USA.
  1567.   */
  1568.  
  1569.  #include "base64.h"
  1570. @@ -122,11 +123,11 @@
  1571.  int base64_decode( unsigned char *dst, size_t *dlen,
  1572.                     const unsigned char *src, size_t slen )
  1573.  {
  1574. -    size_t i, n;
  1575. -    uint32_t j, x;
  1576. +    size_t i, j, n;
  1577. +    unsigned long x;
  1578.      unsigned char *p;
  1579.  
  1580. -    for( i = n = j = 0; i < slen; i++ )
  1581. +    for( i = j = n = 0; i < slen; i++ )
  1582.      {
  1583.          if( ( slen - i ) >= 2 &&
  1584.              src[i] == '\r' && src[i + 1] == '\n' )
  1585. @@ -152,7 +153,7 @@
  1586.  
  1587.      n = ((n * 6) + 7) >> 3;
  1588.  
  1589. -    if( dst == NULL || *dlen < n )
  1590. +    if( *dlen < n )
  1591.      {
  1592.          *dlen = n;
  1593.          return( ERR_BASE64_BUFFER_TOO_SMALL );
  1594. diff -urN ./inadyn-1.99.15/src/cache.c ./inadyn_padavan/src/cache.c
  1595. --- ./inadyn-1.99.15/src/cache.c        2016-01-22 13:41:48.000000000 +0300
  1596. +++ ./inadyn_padavan/src/cache.c        2016-01-22 14:22:01.000000000 +0300
  1597. @@ -42,7 +42,7 @@
  1598.  /* Optional setting, e.g., --cache-dir=/etc */
  1599.  char *cache_dir = NULL;
  1600.  
  1601. -static int nslookup(ddns_alias_t *alias)
  1602. +static int nslookup(ddns_alias_t *alias, int verbose)
  1603.  {
  1604.         int error;
  1605.         struct addrinfo hints;
  1606. @@ -61,9 +61,12 @@
  1607.                 /* DNS reply for alias found, convert to IP# */
  1608.                 if (!getnameinfo(result->ai_addr, result->ai_addrlen, address, sizeof(address), NULL, 0, NI_NUMERICHOST)) {
  1609.                         /* Update local record for next checkip call. */
  1610. -                       alias->last_update = 0;
  1611. -                       strlcpy(alias->address, address, sizeof(alias->address));
  1612. -                       logit(LOG_INFO, "Resolving hostname %s => IP# %s", alias->name, address);
  1613. +                       strncpy(alias->address, address, sizeof(alias->address));
  1614. +
  1615. +                       alias->last_update = time(NULL);
  1616. +                       write_cache_file(alias);
  1617. +                       if (verbose > 0)
  1618. +                               logit(LOG_INFO, "Resolving hostname %s => IP# %s", alias->name, address);
  1619.                 }
  1620.  
  1621.                 freeaddrinfo(result);
  1622. @@ -75,35 +78,37 @@
  1623.         return 1;
  1624.  }
  1625.  
  1626. -static void read_one(ddns_alias_t *alias, int nonslookup)
  1627. +static void read_one(ddns_alias_t *alias, int nonslookup, int verbose)
  1628.  {
  1629.         FILE *fp;
  1630. -        char path[256];
  1631. +       char path[256];
  1632.  
  1633. -        alias->last_update = 0;
  1634. -        memset(alias->address, 0, sizeof(alias->address));
  1635. +       alias->last_update = 0;
  1636. +       memset(alias->address, 0, sizeof(alias->address));
  1637.  
  1638.         cache_file(alias->name, path, sizeof(path));
  1639.         fp = fopen(path, "r");
  1640.         if (!fp) {
  1641. -                if (nonslookup)
  1642. -                        return;
  1643. +               if (nonslookup)
  1644. +                       return;
  1645.  
  1646.                 /* Try a DNS lookup of our last known IP#. */
  1647. -                nslookup(alias);
  1648. +               nslookup(alias, verbose);
  1649.         } else {
  1650.                 struct stat st;
  1651.                 char address[MAX_ADDRESS_LEN];
  1652.  
  1653.                 if (fgets(address, sizeof(address), fp)) {
  1654. -                       logit(LOG_INFO, "Cached IP# %s for %s from previous invocation.", address, alias->name);
  1655. -                        strlcpy(alias->address, address, sizeof(alias->address));
  1656. +                       if (verbose > 0)
  1657. +                               logit(LOG_INFO, "Cached IP# %s for %s from previous invocation.", address, alias->name);
  1658. +                       strncpy(alias->address, address, sizeof(alias->address));
  1659.                 }
  1660.  
  1661.                 /* Initialize time since last update from modification time of cache file. */
  1662.                 if (!fstat(fileno(fp), &st)) {
  1663.                         alias->last_update = st.st_mtime;
  1664. -                       logit(LOG_INFO, "Last update of %s on %s", alias->name, ctime(&st.st_mtime));
  1665. +                       if (verbose > 0)
  1666. +                               logit(LOG_INFO, "Last update of %s on %s", alias->name, ctime(&st.st_mtime));
  1667.                 }
  1668.  
  1669.                 fclose(fp);
  1670. @@ -134,34 +139,38 @@
  1671.  {
  1672.         int i, j;
  1673.  
  1674. -        /* Clear DNS cache before querying for the IP below, this to
  1675. -         * prevent any artefacts from, e.g., nscd, which is a known
  1676. -         * problem with DDNS clients. */
  1677. -        res_init();
  1678. +       /* Clear DNS cache before querying for the IP below, this to
  1679. +        * prevent any artefacts from, e.g., nscd, which is a known
  1680. +        * problem with DDNS clients. */
  1681. +       res_init();
  1682.  
  1683.         if (!ctx)
  1684.                 return RC_INVALID_POINTER;
  1685.  
  1686. -        for (i = 0; i < ctx->info_count; i++) {
  1687. -                ddns_info_t *info = &ctx->info[i];
  1688. -                int nonslookup;
  1689. -
  1690. -                /* Exception for tunnelbroker.net - no name to lookup */
  1691. -                nonslookup = !strcmp(info->system->name, "ipv6tb@he.net");
  1692. +       for (i = 0; i < ctx->info_count; i++) {
  1693. +               ddns_info_t *info = &ctx->info[i];
  1694. +               int nonslookup = 0;
  1695. +               /* Exception for tunnelbroker.net - no name to lookup */
  1696. +               /* Exception for ipv6tb@netassist.ua - no name to lookup */
  1697. +               /* Exception for register@asus.com - no name to lookup */
  1698. +               if (!strcmp(info->system->name, "ipv6tb@netassist.ua") ||
  1699. +                   !strcmp(info->system->name, "default@tunnelbroker.net") ||
  1700. +                   !strcmp(info->system->name, "register@asus.com"))
  1701. +                       nonslookup = 1;
  1702.  // XXX: TODO better plugin identifiction here
  1703. -                for (j = 0; j < info->alias_count; j++)
  1704. -                        read_one(&info->alias[j], nonslookup);
  1705. -        }
  1706. -
  1707. +               for (j = 0; j < info->alias_count; j++)
  1708. +                       read_one(&info->alias[j], nonslookup, ctx->dbg.level);
  1709. +       }
  1710. +
  1711.         return 0;
  1712.  }
  1713.  
  1714.  /* Update cache with new IP
  1715. - *  /var/run/inadyn/my.server.name.cache { LAST-IPADDR } MTIME */
  1716. + *  /var/run/my.server.name.cache { LAST-IPADDR } MTIME */
  1717.  int write_cache_file(ddns_alias_t *alias)
  1718.  {
  1719.         FILE *fp;
  1720. -        char path[256];
  1721. +       char path[256];
  1722.  
  1723.         cache_file(alias->name, path, sizeof(path));
  1724.         fp = fopen(path, "w");
  1725. diff -urN ./inadyn-1.99.15/src/cmd.c ./inadyn_padavan/src/cmd.c
  1726. --- ./inadyn-1.99.15/src/cmd.c  2016-01-22 13:41:48.000000000 +0300
  1727. +++ ./inadyn_padavan/src/cmd.c  2016-01-22 14:22:01.000000000 +0300
  1728. @@ -114,7 +114,7 @@
  1729.  
  1730.         {"-f", 1, {get_forced_update_period_handler, NULL}, ""},
  1731.         {"--forced-update", 1, {get_forced_update_period_handler, NULL},
  1732. -        "<SEC>\n" "\t\t\tForced DDNS server update interval. Default: 30 days"},
  1733. +        "<SEC>\n" "\t\t\tForced DDNS server update interval. Default: 10 days"},
  1734.         {"--forced_update_period", 1, {get_forced_update_period_handler, NULL}, NULL},  /* COMPAT */
  1735.  
  1736.         {"-F", 1, {get_options_from_file_handler, NULL}, ""},
  1737. @@ -180,21 +180,25 @@
  1738.          "\t\t\t     default@tzo.com\n"
  1739.          "\t\t\t     dyndns@3322.org\n"
  1740.          "\t\t\t     default@dnsomatic.com\n"
  1741. -        "\t\t\t     ipv6tb@he.net\n"
  1742.          "\t\t\t     dyndns@he.net\n"
  1743. +        "\t\t\t     default@tunnelbroker.net\n"
  1744.          "\t\t\t     default@dynsip.org\n"
  1745.          "\t\t\t     default@sitelutions.com\n"
  1746.          "\t\t\t     default@dnsexit.com\n"
  1747.          "\t\t\t     default@changeip.com\n"
  1748.          "\t\t\t     default@zerigo.com\n"
  1749.          "\t\t\t     default@dhis.org\n"
  1750. -        "\t\t\t     ipv4@nsupdate.info\n"
  1751. +        "\t\t\t     default@nic.ru\n"
  1752.          "\t\t\t     default@duckdns.org\n"
  1753.          "\t\t\t     default@loopia.com\n"
  1754.          "\t\t\t     default@domains.google.com\n"
  1755.          "\t\t\t     default@ovh.com\n"
  1756. +        "\t\t\t     default@dtdns.com\n"
  1757.          "\t\t\t     default@gira.de\n"
  1758.          "\t\t\t     default@duiadns.net\n"
  1759. +        "\t\t\t     ipv4@nsupdate.info\n"
  1760. +        "\t\t\t     update@asus.com, register@asus.com\n"
  1761. +        "\t\t\t     ipv6tb@netassist.ua\n"
  1762.          "\t\t\t     custom@http_srv_basic_auth"},
  1763.         {"--dyndns_system", 1, {get_dyndns_system_handler, NULL}, NULL},
  1764.  
  1765. @@ -209,7 +213,7 @@
  1766.         {"--update_period_sec", 1, {get_update_period_sec_handler, NULL}, NULL},
  1767.         {"--update_period", 1, {get_update_period_handler, NULL}, NULL}, /* TODO: Replaced with startup-delay, remove in 2.0 */
  1768.  
  1769. -       {"-P", 1,        {set_pidfile, NULL}, ""},
  1770. +       {"-P", 1, {set_pidfile, NULL}, ""},
  1771.         {"--pidfile", 1, {set_pidfile, NULL}, "<FILE>\n" "\t\t\tSet pidfile, default " DEFAULT_PIDFILE},
  1772.  
  1773.  #ifdef ENABLE_SSL
  1774. @@ -319,7 +323,7 @@
  1775.         if (!p)
  1776.                 return RC_OUT_OF_MEMORY;
  1777.  
  1778. -       strlcpy(p, p_val, strlen(p_val) + 1);
  1779. +       strcpy(p, p_val);
  1780.         cmd->argv[cmd->argc] = p;
  1781.         cmd->argc++;
  1782.  
  1783. @@ -479,7 +483,7 @@
  1784.  
  1785.         ctx->update_once = 1;
  1786.         ctx->total_iterations = 1;
  1787. -       ctx->dbg.level = 5;
  1788. +       ctx->dbg.level = 1;
  1789.  
  1790.         return 0;
  1791.  }
  1792. @@ -550,10 +554,10 @@
  1793.         if (ctx == NULL)
  1794.                 return RC_INVALID_POINTER;
  1795.  
  1796. -       if (sizeof(ctx->dbg.p_logfilename) < strlen(cmd->argv[num]))
  1797. +       if (sizeof(ctx->dbg.p_logfilename) <= strlen(cmd->argv[num]))
  1798.                 return RC_DYNDNS_BUFFER_TOO_SMALL;
  1799.  
  1800. -       strlcpy(ctx->dbg.p_logfilename, cmd->argv[num], sizeof(ctx->dbg.p_logfilename));
  1801. +       strcpy(ctx->dbg.p_logfilename, cmd->argv[num]);
  1802.  
  1803.         return 0;
  1804.  }
  1805. @@ -561,14 +565,17 @@
  1806.  static int get_username_handler(cmd_data_t *cmd, int num, void *context)
  1807.  {
  1808.         ddns_t *ctx = (ddns_t *)context;
  1809. +       ddns_info_t *info;
  1810.  
  1811.         if (ctx == NULL)
  1812.                 return RC_INVALID_POINTER;
  1813.  
  1814. -       if (sizeof(ctx->info[infid].creds.username) < strlen(cmd->argv[num]))
  1815. +       info = &ctx->info[infid];
  1816. +
  1817. +       if (sizeof(info->creds.username) <= strlen(cmd->argv[num]))
  1818.                 return RC_DYNDNS_BUFFER_TOO_SMALL;
  1819.  
  1820. -       strlcpy(ctx->info[infid].creds.username, cmd->argv[num], sizeof(ctx->info[infid].creds.username));
  1821. +       strcpy(info->creds.username, cmd->argv[num]);
  1822.  
  1823.         return 0;
  1824.  }
  1825. @@ -576,14 +583,17 @@
  1826.  static int get_password_handler(cmd_data_t *cmd, int num, void *context)
  1827.  {
  1828.         ddns_t *ctx = (ddns_t *)context;
  1829. +       ddns_info_t *info;
  1830.  
  1831.         if (ctx == NULL)
  1832.                 return RC_INVALID_POINTER;
  1833.  
  1834. -       if (sizeof(ctx->info[infid].creds.password) < strlen(cmd->argv[num]))
  1835. +       info = &ctx->info[infid];
  1836. +
  1837. +       if (sizeof(info->creds.password) <= strlen(cmd->argv[num]))
  1838.                 return RC_DYNDNS_BUFFER_TOO_SMALL;
  1839.  
  1840. -       strlcpy(ctx->info[infid].creds.password, cmd->argv[num], sizeof(ctx->info[infid].creds.password));
  1841. +       strcpy(info->creds.password, cmd->argv[num]);
  1842.  
  1843.         return 0;
  1844.  }
  1845. @@ -591,42 +601,46 @@
  1846.  static int get_alias_handler(cmd_data_t *cmd, int num, void *context)
  1847.  {
  1848.         ddns_t *ctx = (ddns_t *)context;
  1849. +       ddns_info_t *info;
  1850.  
  1851.         if (ctx == NULL)
  1852.                 return RC_INVALID_POINTER;
  1853.  
  1854. -       if (ctx->info[infid].alias_count >= DYNDNS_MAX_ALIAS_NUMBER)
  1855. +       info = &ctx->info[infid];
  1856. +
  1857. +       if (info->alias_count >= DYNDNS_MAX_ALIAS_NUMBER)
  1858.                 return RC_DYNDNS_TOO_MANY_ALIASES;
  1859.  
  1860. -       if (sizeof(ctx->info[infid].alias[ctx->info[infid].alias_count].name) < strlen(cmd->argv[num]))
  1861. +       if (sizeof(info->alias[info->alias_count].name) <= strlen(cmd->argv[num]))
  1862.                 return RC_DYNDNS_BUFFER_TOO_SMALL;
  1863.  
  1864. -       strlcpy(ctx->info[infid].alias[ctx->info[infid].alias_count].name, cmd->argv[num], sizeof(ctx->info[infid].alias[ctx->info[infid].alias_count].name));
  1865. -       ctx->info[infid].alias_count++;
  1866. +       strcpy(info->alias[info->alias_count].name, cmd->argv[num]);
  1867. +       info->alias_count++;
  1868.  
  1869.         return 0;
  1870.  }
  1871.  
  1872. -/* p_len is the size of the p_dest_name buffer */
  1873. -static int get_name_and_port(char *p_src, char *p_dest_name, int *p_dest_port, size_t p_len)
  1874. +static int get_name_and_port(const char *p_src, char *p_dest_name, size_t dest_size, int *p_dest_port)
  1875.  {
  1876.         const char *p_port = strstr(p_src, ":");
  1877.  
  1878.         if (p_port) {
  1879. -               int port_nr, port_ok = sscanf(p_port + 1, "%d", &port_nr);
  1880. -               size_t len;
  1881. +               int port_nr, len;
  1882. +               int port_ok = sscanf(p_port + 1, "%d", &port_nr);
  1883.  
  1884.                 if (port_ok != 1)
  1885.                         return RC_DYNDNS_INVALID_OPTION;
  1886. -
  1887. -               *p_dest_port = port_nr;
  1888.                 len = p_port - p_src;
  1889. -               if (len >= p_len)
  1890. -                       len = p_len - 1;
  1891. +               if (dest_size <= (size_t)len)
  1892. +                       return RC_DYNDNS_BUFFER_TOO_SMALL;
  1893.                 memcpy(p_dest_name, p_src, len);
  1894.                 p_dest_name[len] = 0;
  1895. +               *p_dest_port = port_nr;
  1896.         } else {
  1897. -               strlcpy(p_dest_name, p_src, p_len);
  1898. +               if (dest_size <= strlen(p_src))
  1899. +                       return RC_DYNDNS_BUFFER_TOO_SMALL;
  1900. +               strcpy(p_dest_name, p_src);
  1901. +               *p_dest_port = -1;
  1902.         }
  1903.  
  1904.         return 0;
  1905. @@ -641,25 +655,24 @@
  1906.  static int get_checkip_name_handler(cmd_data_t *cmd, int num, void *context)
  1907.  {
  1908.         ddns_t *ctx = (ddns_t *)context;
  1909. +       ddns_info_t *info;
  1910.         int rc;
  1911.         int port = -1;
  1912.  
  1913.         if (ctx == NULL)
  1914.                 return RC_INVALID_POINTER;
  1915.  
  1916. -       /*checkip_name */
  1917. -       if (sizeof(ctx->info[infid].checkip_name) < strlen(cmd->argv[num]) + 1)
  1918. -               return RC_DYNDNS_BUFFER_TOO_SMALL;
  1919. +       info = &ctx->info[infid];
  1920.  
  1921. -       ctx->info[infid].checkip_name.port = HTTP_DEFAULT_PORT;
  1922. -       rc = get_name_and_port(cmd->argv[num], ctx->info[infid].checkip_name.name, &port, sizeof(ctx->info[infid].checkip_name.name));
  1923. +       info->checkip_name.port = HTTP_DEFAULT_PORT;
  1924. +       rc = get_name_and_port(cmd->argv[num], info->checkip_name.name, sizeof(info->checkip_name.name), &port);
  1925.         if (rc == 0 && port != -1)
  1926. -               ctx->info[infid].checkip_name.port = port;
  1927. +               info->checkip_name.port = port;
  1928.  
  1929. -       if (sizeof(ctx->info[infid].checkip_url) < strlen(cmd->argv[num + 1]) + 1)
  1930. +       if (sizeof(info->checkip_url) <= strlen(cmd->argv[num + 1]))
  1931.                 return RC_DYNDNS_BUFFER_TOO_SMALL;
  1932.  
  1933. -       strlcpy(ctx->info[infid].checkip_url, cmd->argv[num + 1], sizeof(ctx->info[infid].checkip_url));
  1934. +       strcpy(info->checkip_url, cmd->argv[num + 1]);
  1935.  
  1936.         return rc;
  1937.  }
  1938. @@ -667,19 +680,19 @@
  1939.  static int get_dns_server_name_handler(cmd_data_t *cmd, int num, void *context)
  1940.  {
  1941.         ddns_t *ctx = (ddns_t *)context;
  1942. +       ddns_info_t *info;
  1943.         int rc;
  1944.         int port = -1;
  1945.  
  1946.         if (ctx == NULL)
  1947.                 return RC_INVALID_POINTER;
  1948.  
  1949. -       if (sizeof(ctx->info[infid].server_name) < strlen(cmd->argv[num]))
  1950. -               return RC_DYNDNS_BUFFER_TOO_SMALL;
  1951. +       info = &ctx->info[infid];
  1952.  
  1953. -       ctx->info[infid].server_name.port = HTTP_DEFAULT_PORT;
  1954. -       rc = get_name_and_port(cmd->argv[num], ctx->info[infid].server_name.name, &port, sizeof(ctx->info[infid].server_name.name));
  1955. +       info->server_name.port = HTTP_DEFAULT_PORT;
  1956. +       rc = get_name_and_port(cmd->argv[num], info->server_name.name, sizeof(info->server_name.name), &port);
  1957.         if (rc == 0 && port != -1)
  1958. -               ctx->info[infid].server_name.port = port;
  1959. +               info->server_name.port = port;
  1960.  
  1961.         return rc;
  1962.  }
  1963. @@ -687,14 +700,17 @@
  1964.  int get_dns_server_url_handler(cmd_data_t *cmd, int num, void *context)
  1965.  {
  1966.         ddns_t *ctx = (ddns_t *)context;
  1967. +       ddns_info_t *info;
  1968.  
  1969.         if (ctx == NULL)
  1970.                 return RC_INVALID_POINTER;
  1971.  
  1972. -       if (sizeof(ctx->info[infid].server_url) < strlen(cmd->argv[num]))
  1973. +       info = &ctx->info[infid];
  1974. +
  1975. +       if (sizeof(info->server_url) <= strlen(cmd->argv[num]))
  1976.                 return RC_DYNDNS_BUFFER_TOO_SMALL;
  1977.  
  1978. -       strlcpy(ctx->info[infid].server_url, cmd->argv[num], sizeof(ctx->info[infid].server_url));
  1979. +       strcpy(info->server_url, cmd->argv[num]);
  1980.  
  1981.         return 0;
  1982.  }
  1983. @@ -719,19 +735,19 @@
  1984.  static int get_proxy_server_handler(cmd_data_t *cmd, int num, void *context)
  1985.  {
  1986.         ddns_t *ctx = (ddns_t *)context;
  1987. +       ddns_info_t *info;
  1988.         int rc;
  1989.         int port = -1;
  1990.  
  1991.         if (ctx == NULL)
  1992.                 return RC_INVALID_POINTER;
  1993.  
  1994. -       if (sizeof(ctx->info[infid].proxy_server_name) < strlen(cmd->argv[num]))
  1995. -               return RC_DYNDNS_BUFFER_TOO_SMALL;
  1996. +       info = &ctx->info[infid];
  1997.  
  1998. -       ctx->info[infid].proxy_server_name.port = HTTP_DEFAULT_PORT;
  1999. -       rc = get_name_and_port(cmd->argv[num], ctx->info[infid].proxy_server_name.name, &port, sizeof(ctx->info[infid].proxy_server_name.name));
  2000. +       info->proxy_server_name.port = HTTP_DEFAULT_PORT;
  2001. +       rc = get_name_and_port(cmd->argv[num], info->proxy_server_name.name, sizeof(info->proxy_server_name.name), &port);
  2002.         if (rc == 0 && port != -1)
  2003. -               ctx->info[infid].proxy_server_name.port = port;
  2004. +               info->proxy_server_name.port = port;
  2005.  
  2006.         return rc;
  2007.  }
  2008. @@ -1319,10 +1335,10 @@
  2009.                 int ok = 1;
  2010.                 ddns_info_t *account = &ctx->info[i];
  2011.  
  2012. -               /* username, password, and alias not required for custom setups */
  2013. +               /* username, password not required for custom setups */
  2014.                 if (strncmp(account->system->name, "custom@", 7)) {
  2015.                         check_setting(strlen(account->creds.username), i, "Missing username", &ok);
  2016. -                       check_setting(strlen(account->creds.password), i, "Missing password", &ok);
  2017. +//                     check_setting(strlen(account->creds.password), i, "Missing password", &ok);
  2018.                 }
  2019.                 check_setting(account->alias_count, i, "Missing your alias/hostname", &ok);
  2020.                 check_setting(strlen(account->server_name.name), i,
  2021. @@ -1413,7 +1429,7 @@
  2022.                         };
  2023.                         int custom_argc = sizeof(custom_argv) / sizeof(char *);
  2024.  
  2025. -                       if (ctx->dbg.level)
  2026. +                       if (ctx->dbg.level > 1)
  2027.                                 logit(LOG_NOTICE, "Using default config file %s", DEFAULT_CONFIG_FILE);
  2028.  
  2029.                         if (ctx->cfgfile)
  2030. @@ -1430,34 +1446,36 @@
  2031.                 /* settings that may change due to cmd line options */
  2032.                 i = 0;
  2033.                 do {
  2034. +                       int port;
  2035. +                       size_t src_len;
  2036.                         ddns_info_t *info = &ctx->info[i];
  2037.  
  2038.                         if (strlen(info->checkip_name.name) == 0) {
  2039. -                               if (sizeof(info->checkip_name.name) < strlen(info->system->checkip_name)) {
  2040. -                                       rc = RC_DYNDNS_BUFFER_TOO_SMALL;
  2041. -                                       break;
  2042. +                               if (strlen(info->system->checkip_name) > 0) {
  2043. +                                       port = -1;
  2044. +                                       info->checkip_name.port = HTTP_DEFAULT_PORT;
  2045. +                                       if (get_name_and_port(info->system->checkip_name, info->checkip_name.name, sizeof(info->checkip_name.name), &port) == 0) {
  2046. +                                               if (port > 0 && port < 65535)
  2047. +                                                       info->checkip_name.port = port;
  2048. +                                       }
  2049.                                 }
  2050. -                               strlcpy(info->checkip_name.name, info->system->checkip_name, sizeof(info->checkip_name.name));
  2051. -
  2052. -                               if (sizeof(info->checkip_url) < strlen(info->system->checkip_url)) {
  2053. -                                       rc = RC_DYNDNS_BUFFER_TOO_SMALL;
  2054. -                                       break;
  2055. -                               }
  2056. -                               strlcpy(info->checkip_url, info->system->checkip_url, sizeof(info->checkip_url));
  2057. +                               src_len = strlen(info->system->checkip_url);
  2058. +                               if (src_len > 0 && src_len < sizeof(info->checkip_url))
  2059. +                                       strcpy(info->checkip_url, info->system->checkip_url);
  2060.                         }
  2061.  
  2062.                         if (strlen(info->server_name.name) == 0) {
  2063. -                               if (sizeof(info->server_name.name) < strlen(info->system->server_name)) {
  2064. -                                       rc = RC_DYNDNS_BUFFER_TOO_SMALL;
  2065. -                                       break;
  2066. -                               }
  2067. -                               strlcpy(info->server_name.name, info->system->server_name, sizeof(info->server_name.name));
  2068. -
  2069. -                               if (sizeof(info->server_url) < strlen(info->system->server_url)) {
  2070. -                                       rc = RC_DYNDNS_BUFFER_TOO_SMALL;
  2071. -                                       break;
  2072. +                               if (strlen(info->system->server_name) > 0) {
  2073. +                                       port = -1;
  2074. +                                       info->server_name.port = HTTP_DEFAULT_PORT;
  2075. +                                       if (get_name_and_port(info->system->server_name, info->server_name.name, sizeof(info->server_name.name), &port) == 0) {
  2076. +                                               if (port > 0 && port < 65535)
  2077. +                                                       info->server_name.port = port;
  2078. +                                       }
  2079.                                 }
  2080. -                               strlcpy(info->server_url, info->system->server_url, sizeof(info->server_url));
  2081. +                               src_len = strlen(info->system->server_url);
  2082. +                               if (src_len > 0 && src_len < sizeof(info->server_url))
  2083. +                                       strcpy(info->server_url, info->system->server_url);
  2084.                         }
  2085.                 }
  2086.                 while (++i < ctx->info_count);
  2087. diff -urN ./inadyn-1.99.15/src/ddns.c ./inadyn_padavan/src/ddns.c
  2088. --- ./inadyn-1.99.15/src/ddns.c 2016-01-22 13:41:48.000000000 +0300
  2089. +++ ./inadyn_padavan/src/ddns.c 2016-01-22 14:22:01.000000000 +0300
  2090. @@ -78,7 +78,8 @@
  2091.         char *address;
  2092.         int i, j, sd, anychange = 0;
  2093.  
  2094. -       logit(LOG_INFO, "Checking for IP# change, querying interface %s", ctx->check_interface);
  2095. +       if (ctx->dbg.level > 0)
  2096. +               logit(LOG_INFO, "Checking for IP# change, querying interface %s", ctx->check_interface);
  2097.  
  2098.         sd = socket(PF_INET, SOCK_DGRAM, 0);
  2099.         if (sd < 0) {
  2100. @@ -121,13 +122,15 @@
  2101.                         alias->ip_has_changed = strcmp(alias->address, address) != 0;
  2102.                         if (alias->ip_has_changed) {
  2103.                                 anychange++;
  2104. -                               strlcpy(alias->address, address, sizeof(alias->address));
  2105. +                               strcpy(alias->address, address);
  2106.                         }
  2107.                 }
  2108.         }
  2109.  
  2110. -       if (!anychange)
  2111. -               logit(LOG_INFO, "No IP# change detected, still at %s", address);
  2112. +       if (!anychange) {
  2113. +               if (ctx->dbg.level > 0)
  2114. +                       logit(LOG_INFO, "No IP# change detected, still at %s", address);
  2115. +       }
  2116.  
  2117.         return 0;
  2118.  }
  2119. @@ -145,9 +148,12 @@
  2120.  static int server_transaction(ddns_t *ctx, int servernum)
  2121.  {
  2122.         int rc = 0;
  2123. -       http_t *http = &ctx->http_to_ip_server[servernum];
  2124.         http_trans_t *trans;
  2125. +       http_t *http = &ctx->http_to_ip_server[servernum];
  2126. +       ddns_info_t *info = &ctx->info[servernum];
  2127.  
  2128. +       http->verbose = ctx->dbg.level;
  2129. +       http->ssl_enabled = (info->checkip_name.port == HTTPS_DEFAULT_PORT) ? 1 : 0;
  2130.         DO(http_init(http, "Checking for IP# change"));
  2131.  
  2132.         /* Prepare request for IP server */
  2133. @@ -161,7 +167,7 @@
  2134.         trans->p_rsp       = ctx->work_buf;
  2135.         trans->max_rsp_len = ctx->work_buflen - 1;      /* Save place for terminating \0 in string. */
  2136.  
  2137. -       if (ctx->dbg.level > 2)
  2138. +       if (ctx->dbg.level > 1)
  2139.                 logit(LOG_DEBUG, "Querying DDNS checkip server for my public IP#: %s", ctx->request_buf);
  2140.  
  2141.         rc = http_transaction(http, &ctx->http_transaction);
  2142. @@ -169,7 +175,7 @@
  2143.                 rc = RC_DYNDNS_INVALID_RSP_FROM_IP_SERVER;
  2144.  
  2145.         http_exit(http);
  2146. -       if (ctx->dbg.level > 2)
  2147. +       if (ctx->dbg.level > 1)
  2148.                 logit(LOG_DEBUG, "Checked my IP, return code: %d", rc);
  2149.  
  2150.         return rc;
  2151. @@ -192,8 +198,9 @@
  2152.                 return RC_INVALID_POINTER;
  2153.  
  2154.         haystack = ctx->http_transaction.p_rsp_body;
  2155. -       needle   = haystack;
  2156. -       end      = haystack + strlen(haystack) - 1;
  2157. +       needle = haystack;
  2158. +       end = haystack + strlen(haystack) - 1;
  2159. +
  2160.         while (needle && haystack < end) {
  2161.                 /* Try to find first decimal number (begin of IP) */
  2162.                 needle = strpbrk(haystack, accept);
  2163. @@ -228,15 +235,18 @@
  2164.                                 alias->ip_has_changed = strcmp(alias->address, address) != 0;
  2165.                                 if (alias->ip_has_changed) {
  2166.                                         anychange++;
  2167. -                                       strlcpy(alias->address, address, sizeof(alias->address));
  2168. +                                       strcpy(alias->address, address);
  2169.                                 }
  2170.                         }
  2171.                 }
  2172.  
  2173. -               if (!anychange)
  2174. -                       logit(LOG_INFO, "No IP# change detected, still at %s", address);
  2175. -               else if (ctx->dbg.level > 1)
  2176. -                       logit(LOG_INFO, "Current public IP# %s", address);
  2177. +               if (!anychange) {
  2178. +                       if (ctx->dbg.level > 0)
  2179. +                               logit(LOG_INFO, "No IP# change detected, still at %s", address);
  2180. +               } else {
  2181. +                       if (ctx->dbg.level > 0)
  2182. +                               logit(LOG_INFO, "Current public IP# %s", address);
  2183. +               }
  2184.  
  2185.                 return 0;
  2186.         }
  2187. @@ -301,17 +311,11 @@
  2188.         http_trans_t   trans;
  2189.         http_t        *client = &ctx->http_to_dyndns[info->id];
  2190.  
  2191. +       client->verbose = ctx->dbg.level;
  2192.         client->ssl_enabled = info->ssl_enabled;
  2193. -       if (client->ssl_enabled) /* XXX: Fix this better, possibly in http_init() */
  2194. -               client->tcp.ip.port = 443;
  2195. -
  2196. -       rc = http_init(client, "Sending IP# update to DDNS server");
  2197. -       if (rc) {
  2198. -               /* Update failed, force update again in ctx->cmd_check_period seconds */
  2199. -               ctx->force_addr_update = 1;
  2200. -
  2201. -               return rc;
  2202. -       }
  2203. +       if (info->server_name.port == HTTPS_DEFAULT_PORT)
  2204. +               client->ssl_enabled = 1;
  2205. +       DO(http_init(client, "Sending IP# update to DDNS server"));
  2206.  
  2207.         memset(ctx->work_buf, 0, ctx->work_buflen);
  2208.         memset(ctx->request_buf, 0, ctx->request_buflen);
  2209. @@ -322,20 +326,17 @@
  2210.         trans.p_rsp       = (char *)ctx->work_buf;
  2211.         trans.max_rsp_len = ctx->work_buflen - 1;       /* Save place for a \0 at the end */
  2212.  
  2213. -       if (ctx->dbg.level > 2) {
  2214. +       if (ctx->dbg.level > 1) {
  2215.                 ctx->request_buf[trans.req_len] = 0;
  2216.                 logit(LOG_DEBUG, "Sending alias table update to DDNS server: %s", ctx->request_buf);
  2217.         }
  2218.  
  2219.         rc = http_transaction(client, &trans);
  2220.  
  2221. -       if (ctx->dbg.level > 2)
  2222. +       if (ctx->dbg.level > 1)
  2223.                 logit(LOG_DEBUG, "DDNS server response: %s", trans.p_rsp);
  2224.  
  2225.         if (rc) {
  2226. -               /* Update failed, force update again in ctx->cmd_check_period seconds */
  2227. -               ctx->force_addr_update = 1;
  2228. -
  2229.                 http_exit(client);
  2230.                 return rc;
  2231.         }
  2232. @@ -346,9 +347,6 @@
  2233.                       rc == RC_DYNDNS_RSP_RETRY_LATER ? "Temporary" : "Fatal");
  2234.                 logit(LOG_WARNING, "[%d %s] %s", trans.status, trans.status_desc,
  2235.                       trans.p_rsp_body != trans.p_rsp ? trans.p_rsp_body : "");
  2236. -
  2237. -               /* Update failed, force update again in ctx->cmd_check_period seconds */
  2238. -               ctx->force_addr_update = 1;
  2239.         } else {
  2240.                 logit(LOG_INFO, "Successful alias table update for %s => new IP# %s",
  2241.                       alias->name, alias->address);
  2242. @@ -366,7 +364,7 @@
  2243.  static int update_alias_table(ddns_t *ctx)
  2244.  {
  2245.         int i, j;
  2246. -       int rc = 0, remember = 0;
  2247. +       int rc = 0, remember = RC_OK;
  2248.         int anychange = 0;
  2249.  
  2250.         /* Issue #15: On external trig. force update to random addr. */
  2251. @@ -378,16 +376,16 @@
  2252.                         ddns_info_t *info = &ctx->info[i];
  2253.  
  2254.                         for (j = 0; j < info->alias_count; j++) {
  2255. +                               char backup[SERVER_NAME_LEN];
  2256.                                 ddns_alias_t *alias = &info->alias[j];
  2257. -                               char backup[sizeof(alias->address)];
  2258.  
  2259. -                               strlcpy(backup, alias->address, sizeof(backup));
  2260. +                               strcpy(backup, alias->address);
  2261.  
  2262.                                 /* TODO: Use random address in 203.0.113.0/24 instead */
  2263.                                 snprintf(alias->address, sizeof(alias->address), "203.0.113.42");
  2264.                                 TRY(send_update(ctx, info, alias, NULL));
  2265.  
  2266. -                               strlcpy(alias->address, backup, sizeof(alias->address));
  2267. +                               strcpy(alias->address, backup);
  2268.                         }
  2269.                 }
  2270.  
  2271. @@ -419,10 +417,10 @@
  2272.                                                  ctx->bind_interface);
  2273.                 }
  2274.  
  2275. -               if (RC_DYNDNS_RSP_NOTOK == rc)
  2276. +               if (rc != RC_OK && rc != RC_DYNDNS_RSP_RETRY_LATER)
  2277.                         remember = rc;
  2278.  
  2279. -               if (RC_DYNDNS_RSP_RETRY_LATER == rc && !remember)
  2280. +               if (rc == RC_DYNDNS_RSP_RETRY_LATER && remember == RC_OK)
  2281.                         remember = rc;
  2282.         }
  2283.  
  2284. @@ -432,18 +430,8 @@
  2285.  static int get_encoded_user_passwd(ddns_t *ctx)
  2286.  {
  2287.         int i, rc = 0;
  2288. -       char *buf = NULL;
  2289. -       size_t len;
  2290. -
  2291. -       /* Take base64 encoding into account when allocating buf */
  2292. -       len = strlen(ctx->info[0].creds.password) + strlen(ctx->info[0].creds.username) + 2;
  2293. -       len = (len / 3 + ((len % 3) ? 1 : 0)) * 4; /* output length = 4 * [input len / 3] */
  2294. -
  2295. -       buf = calloc(len, sizeof(char));
  2296. -       if (!buf)
  2297. -               return RC_OUT_OF_MEMORY;
  2298. -       if (ctx->dbg.level > 2)
  2299. -               logit(LOG_DEBUG, "Allocated %zd bytes buffer %p for temp buffer before encoding.", len, buf);
  2300. +       char buf[1024] = {0};
  2301. +       size_t len, pwlen;
  2302.  
  2303.         for (i = 0; i < ctx->info_count; i++) {
  2304.                 int rc2;
  2305. @@ -456,20 +444,21 @@
  2306.                 /* Concatenate username and password with a ':', without
  2307.                  * snprintf(), since that can cause information loss if
  2308.                  * the password has "\=" or similar in it, issue #57 */
  2309. -               strlcpy(buf, info->creds.username, len);
  2310. -               strlcat(buf, ":", len);
  2311. -               strlcat(buf, info->creds.password, len);
  2312. +               len = MIN(strlen(info->creds.username), sizeof(buf)-3);
  2313. +               if (len > 0)
  2314. +                       strncpy(buf, info->creds.username, len);
  2315. +               buf[len] = 0;
  2316. +               strcat(buf, ":");
  2317. +               pwlen = strlen(buf);
  2318. +               len = MIN(strlen(info->creds.password), sizeof(buf)-pwlen-1);
  2319. +               if (len > 0)
  2320. +                       strncpy(&buf[pwlen], info->creds.password, len);
  2321. +               buf[pwlen+len] = 0;
  2322.  
  2323.                 /* query required buffer size for base64 encoded data */
  2324. -               if (ctx->dbg.level > 2)
  2325. -                       logit(LOG_DEBUG, "Checking required size for base64 encoding of user:pass for %s ...", info->system->name);
  2326.                 base64_encode(NULL, &dlen, (unsigned char *)buf, strlen(buf));
  2327. -
  2328. -               if (ctx->dbg.level > 2)
  2329. -                       logit(LOG_DEBUG, "Allocating %zd bytes buffer for base64 encoding.", dlen);
  2330.                 encode = malloc(dlen);
  2331.                 if (!encode) {
  2332. -                       logit(LOG_WARNING, "Out of memory when base64 encoding user:pass for %s!", info->system->name);
  2333.                         rc = RC_OUT_OF_MEMORY;
  2334.                         break;
  2335.                 }
  2336. @@ -477,23 +466,16 @@
  2337.                 /* encode */
  2338.                 rc2 = base64_encode((unsigned char *)encode, &dlen, (unsigned char *)buf, strlen(buf));
  2339.                 if (rc2 != 0) {
  2340. -                       logit(LOG_WARNING, "Failed base64 encoding of user:pass for %s!", info->system->name);
  2341.                         free(encode);
  2342.                         rc = RC_OUT_BUFFER_OVERFLOW;
  2343.                         break;
  2344.                 }
  2345.  
  2346. -               if (ctx->dbg.level > 2)
  2347. -                       logit(LOG_DEBUG, "Base64 encoded string: %s", encode);
  2348.                 info->creds.encoded_password = encode;
  2349.                 info->creds.encoded = 1;
  2350.                 info->creds.size = strlen(info->creds.encoded_password);
  2351.         }
  2352.  
  2353. -       if (ctx->dbg.level > 2)
  2354. -               logit(LOG_DEBUG, "Freeing temp encoding buffer %p", buf);
  2355. -       free(buf);
  2356. -
  2357.         return rc;
  2358.  }
  2359.  
  2360. @@ -566,7 +548,7 @@
  2361.  
  2362.                 /* Ask IP server something so he will respond and give me my IP */
  2363.                 DO(server_transaction(ctx, servernum));
  2364. -               if (ctx->dbg.level > 2) {
  2365. +               if (ctx->dbg.level > 1) {
  2366.                         logit(LOG_DEBUG, "IP server response:");
  2367.                         logit(LOG_DEBUG, "%s", ctx->work_buf);
  2368.                 }
  2369. @@ -596,21 +578,28 @@
  2370.  
  2371.         /* dyn_dns_update_ip() failed, inform the user the (network) error
  2372.          * is not fatal and that we will retry again in a short while. */
  2373. +       case RC_DYNDNS_RSP_NOTOK:
  2374. +       case RC_DYNDNS_RSP_RETRY_LATER:
  2375. +               ctx->sleep_sec = ctx->error_update_period_sec;
  2376. +               break;
  2377. +
  2378.         case RC_IP_INVALID_REMOTE_ADDR: /* Probably temporary DNS error. */
  2379.         case RC_IP_CONNECT_FAILED:      /* Cannot connect to DDNS server atm. */
  2380.         case RC_IP_SEND_ERROR:
  2381.         case RC_IP_RECV_ERROR:
  2382. +       case RC_HTTPS_NO_SSL_SUPPORT:
  2383. +#ifdef ENABLE_SSL
  2384. +       case RC_HTTPS_SNI_ERROR:
  2385. +       case RC_HTTPS_FAILED_CONNECT:
  2386. +       case RC_HTTPS_FAILED_GETTING_CERT:
  2387. +       case RC_HTTPS_SEND_ERROR:
  2388. +       case RC_HTTPS_RECV_ERROR:
  2389. +#endif
  2390.         case RC_OS_INVALID_IP_ADDRESS:
  2391. -       case RC_DYNDNS_RSP_RETRY_LATER:
  2392.         case RC_DYNDNS_INVALID_RSP_FROM_IP_SERVER:
  2393. -               ctx->sleep_sec = ctx->error_update_period_sec;
  2394. -               logit(LOG_WARNING, "Will retry again in %d sec...", ctx->sleep_sec);
  2395. +               ctx->sleep_sec = DYNDNS_FAILED_UPDATE_PERIOD;
  2396.                 break;
  2397.  
  2398. -       case RC_DYNDNS_RSP_NOTOK:
  2399. -               logit(LOG_ERR, "Error response from DDNS server, exiting!");
  2400. -               return 1;
  2401. -
  2402.         /* All other errors, socket creation failures, invalid pointers etc.  */
  2403.         default:
  2404.                 logit(LOG_ERR, "Unrecoverable error %d, exiting ...", rc);
  2405. @@ -631,6 +620,7 @@
  2406.  int ddns_main_loop(ddns_t *ctx, int argc, char *argv[])
  2407.  {
  2408.         int rc = 0;
  2409. +       int iterations_err = 0;
  2410.         static int first_startup = 1;
  2411.  
  2412.         if (!ctx)
  2413. @@ -681,7 +671,8 @@
  2414.          * requires the correct time.  Sleep can be interrupted with the usual
  2415.          * signals inadyn responds too. */
  2416.         if (first_startup && ctx->startup_delay_sec) {
  2417. -               logit(LOG_NOTICE, "Startup delay: %d sec ...", ctx->startup_delay_sec);
  2418. +               if (ctx->dbg.level > 1)
  2419. +                       logit(LOG_NOTICE, "Startup delay: %d sec ...", ctx->startup_delay_sec);
  2420.                 first_startup = 0;
  2421.  
  2422.                 /* Now sleep a while. Using the time set in sleep_sec data member */
  2423. @@ -689,11 +680,13 @@
  2424.                 wait_for_cmd(ctx);
  2425.  
  2426.                 if (ctx->cmd == CMD_STOP) {
  2427. -                       logit(LOG_INFO, "STOP command received, exiting.");
  2428. +                       if (ctx->dbg.level > 1)
  2429. +                               logit(LOG_INFO, "STOP command received, exiting.");
  2430.                         return 0;
  2431.                 }
  2432.                 if (ctx->cmd == CMD_RESTART) {
  2433. -                       logit(LOG_INFO, "RESTART command received, restarting.");
  2434. +                       if (ctx->dbg.level > 1)
  2435. +                               logit(LOG_INFO, "RESTART command received, restarting.");
  2436.                         return RC_RESTART;
  2437.                 }
  2438.                 if (ctx->cmd == CMD_FORCED_UPDATE) {
  2439. @@ -716,14 +709,18 @@
  2440.         /* DDNS client main loop */
  2441.         while (1) {
  2442.                 rc = check_address(ctx);
  2443. -               if (RC_OK == rc) {
  2444. +               if (rc == RC_OK) {
  2445. +                       iterations_err = 0;
  2446.                         if (ctx->total_iterations != 0 &&
  2447.                             ++ctx->num_iterations >= ctx->total_iterations)
  2448.                                 break;
  2449. +               } else {
  2450. +                       iterations_err++;
  2451.                 }
  2452.  
  2453.                 if (ctx->cmd == CMD_RESTART) {
  2454. -                       logit(LOG_INFO, "RESTART command received. Restarting.");
  2455. +                       if (ctx->dbg.level > 1)
  2456. +                               logit(LOG_INFO, "RESTART command received. Restarting.");
  2457.                         ctx->cmd = NO_CMD;
  2458.                         rc = RC_RESTART;
  2459.                         break;
  2460. @@ -733,16 +730,49 @@
  2461.                 if (check_error(ctx, rc))
  2462.                         break;
  2463.  
  2464. +               /* prevent infinity loop on fixed number iterations after many failed update */
  2465. +               if (ctx->total_iterations > 0 && iterations_err > ctx->total_iterations)
  2466. +                       break;
  2467. +
  2468. +               /* check special case for ONCE mode */
  2469. +               if (ctx->update_once == 1) {
  2470. +                       /* terminate now after server kick ass */
  2471. +                       if (rc == RC_DYNDNS_RSP_NOTOK ||
  2472. +                           rc == RC_DYNDNS_INVALID_RSP_FROM_IP_SERVER)
  2473. +                               break;
  2474. +
  2475. +                       /* else minimal sleep for try again */
  2476. +                       ctx->sleep_sec = DYNDNS_MIN_SLEEP;
  2477. +               } else {
  2478. +                       /* dynamic increase interval after 3x errors (upper limit 60 min) */
  2479. +                       if (iterations_err > 3) {
  2480. +                               int sleep_sec = ctx->sleep_sec * (iterations_err - 2);
  2481. +                               if (sleep_sec > 3600)
  2482. +                                       sleep_sec = 3600;
  2483. +                               ctx->sleep_sec = sleep_sec;
  2484. +                       }
  2485. +               }
  2486. +
  2487. +               if (rc != RC_OK) {
  2488. +                       int minutes = ctx->sleep_sec / 60;
  2489. +                       if (!minutes)
  2490. +                               logit(LOG_WARNING, "Will retry again after %d %s...", ctx->sleep_sec, "sec");
  2491. +                       else
  2492. +                               logit(LOG_WARNING, "Will retry again after %d %s...", minutes, "min");
  2493. +               }
  2494. +
  2495.                 /* Now sleep a while. Using the time set in sleep_sec data member */
  2496.                 wait_for_cmd(ctx);
  2497.  
  2498.                 if (ctx->cmd == CMD_STOP) {
  2499. -                       logit(LOG_INFO, "STOP command received, exiting.");
  2500. +                       if (ctx->dbg.level > 1)
  2501. +                               logit(LOG_INFO, "STOP command received, exiting.");
  2502.                         rc = 0;
  2503.                         break;
  2504.                 }
  2505.                 if (ctx->cmd == CMD_RESTART) {
  2506. -                       logit(LOG_INFO, "RESTART command received, restarting.");
  2507. +                       if (ctx->dbg.level > 1)
  2508. +                               logit(LOG_INFO, "RESTART command received, restarting.");
  2509.                         rc = RC_RESTART;
  2510.                         break;
  2511.                 }
  2512. diff -urN ./inadyn-1.99.15/src/error.c ./inadyn_padavan/src/error.c
  2513. --- ./inadyn-1.99.15/src/error.c        2016-01-22 13:41:47.000000000 +0300
  2514. +++ ./inadyn_padavan/src/error.c        2016-01-22 14:22:01.000000000 +0300
  2515. @@ -20,7 +20,7 @@
  2516.   * Boston, MA  02110-1301, USA.
  2517.   */
  2518.  
  2519. -#include "../include/error.h"
  2520. +#include "error.h"
  2521.  #include <stdlib.h>
  2522.  
  2523.  typedef struct {
  2524. diff -urN ./inadyn-1.99.15/src/http.c ./inadyn_padavan/src/http.c
  2525. --- ./inadyn-1.99.15/src/http.c 2016-01-22 13:41:47.000000000 +0300
  2526. +++ ./inadyn_padavan/src/http.c 2016-01-22 14:22:01.000000000 +0300
  2527. @@ -71,9 +71,12 @@
  2528.  {
  2529.         int rc = 0;
  2530.  
  2531. +       if (client->ssl_enabled)
  2532. +               client->tcp.ip.port = HTTPS_DEFAULT_PORT;
  2533. +
  2534.         do {
  2535.                 TRY(local_set_params(client));
  2536. -               TRY(tcp_init(&client->tcp, msg));
  2537. +               TRY(tcp_init(&client->tcp, msg, client->verbose));
  2538.                 if (client->ssl_enabled)
  2539.                         TRY(ssl_init(client, msg));
  2540.         }
  2541. diff -urN ./inadyn-1.99.15/src/ip.c ./inadyn_padavan/src/ip.c
  2542. --- ./inadyn-1.99.15/src/ip.c   2016-01-22 13:41:47.000000000 +0300
  2543. +++ ./inadyn_padavan/src/ip.c   2016-01-22 14:22:01.000000000 +0300
  2544. @@ -32,10 +32,10 @@
  2545.  #include <errno.h>
  2546.  #include <stdio.h>
  2547.  
  2548. -#include "libite/lite.h"
  2549.  #include "debug.h"
  2550.  #include "ip.h"
  2551.  
  2552. +
  2553.  int ip_construct(ip_sock_t *ip)
  2554.  {
  2555.         ASSERT(ip);
  2556. @@ -91,7 +91,7 @@
  2557.                         }
  2558.  
  2559.                         memset(&ifr, 0, sizeof(struct ifreq));
  2560. -                       strlcpy(ifr.ifr_name, ip->ifname, IFNAMSIZ);
  2561. +                       strncpy(ifr.ifr_name, ip->ifname, IFNAMSIZ);
  2562.                         if (ioctl(sd, SIOCGIFADDR, &ifr) != -1) {
  2563.                                 ip->local_addr.sin_family = AF_INET;
  2564.                                 ip->local_addr.sin_port = htons(0);
  2565. @@ -223,7 +223,6 @@
  2566.                 bytes = recv(ip->socket, buf + total_bytes, chunk_size, 0);
  2567.                 if (bytes < 0) {
  2568.                         int code = os_get_socket_error();
  2569. -
  2570.                         logit(LOG_WARNING, "Network error while waiting for reply: %s",
  2571.                               strerror(code));
  2572.                         rc = RC_IP_RECV_ERROR;
  2573. diff -urN ./inadyn-1.99.15/src/md5.c ./inadyn_padavan/src/md5.c
  2574. --- ./inadyn-1.99.15/src/md5.c  2016-01-22 13:41:47.000000000 +0300
  2575. +++ ./inadyn_padavan/src/md5.c  2016-01-22 14:22:01.000000000 +0300
  2576. @@ -1,27 +1,29 @@
  2577. -/*
  2578. - *  RFC 1321 compliant MD5 implementation
  2579. +/* RFC 1321 compliant MD5 implementation
  2580.   *
  2581. - *  Copyright (C) 2006-2013, Brainspark B.V.
  2582. + * Copyright (C) 2006-2010, Brainspark B.V.
  2583.   *
  2584. - *  This file is part of PolarSSL (http://www.polarssl.org)
  2585. - *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  2586. + * This file is part of PolarSSL (http://www.polarssl.org)
  2587. + * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  2588.   *
  2589. - *  All rights reserved.
  2590. + * All rights reserved.
  2591.   *
  2592. - *  This program is free software; you can redistribute it and/or modify
  2593. - *  it under the terms of the GNU General Public License as published by
  2594. - *  the Free Software Foundation; either version 2 of the License, or
  2595. - *  (at your option) any later version.
  2596. + * This program is free software; you can redistribute it and/or
  2597. + * modify it under the terms of the GNU General Public License
  2598. + * as published by the Free Software Foundation; either version 2
  2599. + * of the License, or (at your option) any later version.
  2600.   *
  2601. - *  This program is distributed in the hope that it will be useful,
  2602. - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  2603. - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2604. - *  GNU General Public License for more details.
  2605. + * This program is distributed in the hope that it will be useful,
  2606. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2607. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2608. + * GNU General Public License for more details.
  2609.   *
  2610. - *  You should have received a copy of the GNU General Public License along
  2611. - *  with this program; if not, write to the Free Software Foundation, Inc.,
  2612. - *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  2613. + * You should have received a copy of the GNU General Public License
  2614. + * along with this program; if not, visit the Free Software Foundation
  2615. + * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the
  2616. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  2617. + * Boston, MA 02110-1301, USA.
  2618.   */
  2619. +
  2620.  /*
  2621.   *  The MD5 algorithm was designed by Ron Rivest in 1991.
  2622.   *
  2623. @@ -33,18 +35,18 @@
  2624.  /*
  2625.   * 32-bit integer manipulation macros (little endian)
  2626.   */
  2627. -#ifndef GET_UINT32_LE
  2628. -#define GET_UINT32_LE(n,b,i)                            \
  2629. +#ifndef GET_ULONG_LE
  2630. +#define GET_ULONG_LE(n,b,i)                             \
  2631.  {                                                       \
  2632. -    (n) = ( (uint32_t) (b)[(i)    ]       )             \
  2633. -        | ( (uint32_t) (b)[(i) + 1] <<  8 )             \
  2634. -        | ( (uint32_t) (b)[(i) + 2] << 16 )             \
  2635. -        | ( (uint32_t) (b)[(i) + 3] << 24 );            \
  2636. +    (n) = ( (unsigned long) (b)[(i)    ]       )        \
  2637. +        | ( (unsigned long) (b)[(i) + 1] <<  8 )        \
  2638. +        | ( (unsigned long) (b)[(i) + 2] << 16 )        \
  2639. +        | ( (unsigned long) (b)[(i) + 3] << 24 );       \
  2640.  }
  2641.  #endif
  2642.  
  2643. -#ifndef PUT_UINT32_LE
  2644. -#define PUT_UINT32_LE(n,b,i)                            \
  2645. +#ifndef PUT_ULONG_LE
  2646. +#define PUT_ULONG_LE(n,b,i)                             \
  2647.  {                                                       \
  2648.      (b)[(i)    ] = (unsigned char) ( (n)       );       \
  2649.      (b)[(i) + 1] = (unsigned char) ( (n) >>  8 );       \
  2650. @@ -69,24 +71,24 @@
  2651.  
  2652.  static void md5_process( md5_context *ctx, const unsigned char data[64] )
  2653.  {
  2654. -    uint32_t X[16], A, B, C, D;
  2655. +    unsigned long X[16], A, B, C, D;
  2656.  
  2657. -    GET_UINT32_LE( X[ 0], data,  0 );
  2658. -    GET_UINT32_LE( X[ 1], data,  4 );
  2659. -    GET_UINT32_LE( X[ 2], data,  8 );
  2660. -    GET_UINT32_LE( X[ 3], data, 12 );
  2661. -    GET_UINT32_LE( X[ 4], data, 16 );
  2662. -    GET_UINT32_LE( X[ 5], data, 20 );
  2663. -    GET_UINT32_LE( X[ 6], data, 24 );
  2664. -    GET_UINT32_LE( X[ 7], data, 28 );
  2665. -    GET_UINT32_LE( X[ 8], data, 32 );
  2666. -    GET_UINT32_LE( X[ 9], data, 36 );
  2667. -    GET_UINT32_LE( X[10], data, 40 );
  2668. -    GET_UINT32_LE( X[11], data, 44 );
  2669. -    GET_UINT32_LE( X[12], data, 48 );
  2670. -    GET_UINT32_LE( X[13], data, 52 );
  2671. -    GET_UINT32_LE( X[14], data, 56 );
  2672. -    GET_UINT32_LE( X[15], data, 60 );
  2673. +    GET_ULONG_LE( X[ 0], data,  0 );
  2674. +    GET_ULONG_LE( X[ 1], data,  4 );
  2675. +    GET_ULONG_LE( X[ 2], data,  8 );
  2676. +    GET_ULONG_LE( X[ 3], data, 12 );
  2677. +    GET_ULONG_LE( X[ 4], data, 16 );
  2678. +    GET_ULONG_LE( X[ 5], data, 20 );
  2679. +    GET_ULONG_LE( X[ 6], data, 24 );
  2680. +    GET_ULONG_LE( X[ 7], data, 28 );
  2681. +    GET_ULONG_LE( X[ 8], data, 32 );
  2682. +    GET_ULONG_LE( X[ 9], data, 36 );
  2683. +    GET_ULONG_LE( X[10], data, 40 );
  2684. +    GET_ULONG_LE( X[11], data, 44 );
  2685. +    GET_ULONG_LE( X[12], data, 48 );
  2686. +    GET_ULONG_LE( X[13], data, 52 );
  2687. +    GET_ULONG_LE( X[14], data, 56 );
  2688. +    GET_ULONG_LE( X[15], data, 60 );
  2689.  
  2690.  #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
  2691.  
  2692. @@ -196,7 +198,7 @@
  2693.  void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen )
  2694.  {
  2695.      size_t fill;
  2696. -    uint32_t left;
  2697. +    unsigned long left;
  2698.  
  2699.      if( ilen <= 0 )
  2700.          return;
  2701. @@ -204,15 +206,16 @@
  2702.      left = ctx->total[0] & 0x3F;
  2703.      fill = 64 - left;
  2704.  
  2705. -    ctx->total[0] += (uint32_t) ilen;
  2706. +    ctx->total[0] += (unsigned long) ilen;
  2707.      ctx->total[0] &= 0xFFFFFFFF;
  2708.  
  2709. -    if( ctx->total[0] < (uint32_t) ilen )
  2710. +    if( ctx->total[0] < (unsigned long) ilen )
  2711.          ctx->total[1]++;
  2712.  
  2713.      if( left && ilen >= fill )
  2714.      {
  2715. -        memcpy( (void *) (ctx->buffer + left), input, fill );
  2716. +        memcpy( (void *) (ctx->buffer + left),
  2717. +                (void *) input, fill );
  2718.          md5_process( ctx, ctx->buffer );
  2719.          input += fill;
  2720.          ilen  -= fill;
  2721. @@ -228,7 +231,8 @@
  2722.  
  2723.      if( ilen > 0 )
  2724.      {
  2725. -        memcpy( (void *) (ctx->buffer + left), input, ilen );
  2726. +        memcpy( (void *) (ctx->buffer + left),
  2727. +                (void *) input, ilen );
  2728.      }
  2729.  }
  2730.  
  2731. @@ -245,27 +249,27 @@
  2732.   */
  2733.  void md5_finish( md5_context *ctx, unsigned char output[16] )
  2734.  {
  2735. -    uint32_t last, padn;
  2736. -    uint32_t high, low;
  2737. +    unsigned long last, padn;
  2738. +    unsigned long high, low;
  2739.      unsigned char msglen[8];
  2740.  
  2741.      high = ( ctx->total[0] >> 29 )
  2742.           | ( ctx->total[1] <<  3 );
  2743.      low  = ( ctx->total[0] <<  3 );
  2744.  
  2745. -    PUT_UINT32_LE( low,  msglen, 0 );
  2746. -    PUT_UINT32_LE( high, msglen, 4 );
  2747. +    PUT_ULONG_LE( low,  msglen, 0 );
  2748. +    PUT_ULONG_LE( high, msglen, 4 );
  2749.  
  2750.      last = ctx->total[0] & 0x3F;
  2751.      padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
  2752.  
  2753. -    md5_update( ctx, md5_padding, padn );
  2754. +    md5_update( ctx, (unsigned char *) md5_padding, padn );
  2755.      md5_update( ctx, msglen, 8 );
  2756.  
  2757. -    PUT_UINT32_LE( ctx->state[0], output,  0 );
  2758. -    PUT_UINT32_LE( ctx->state[1], output,  4 );
  2759. -    PUT_UINT32_LE( ctx->state[2], output,  8 );
  2760. -    PUT_UINT32_LE( ctx->state[3], output, 12 );
  2761. +    PUT_ULONG_LE( ctx->state[0], output,  0 );
  2762. +    PUT_ULONG_LE( ctx->state[1], output,  4 );
  2763. +    PUT_ULONG_LE( ctx->state[2], output,  8 );
  2764. +    PUT_ULONG_LE( ctx->state[3], output, 12 );
  2765.  }
  2766.  
  2767.  /*
  2768. diff -urN ./inadyn-1.99.15/src/os.c ./inadyn_padavan/src/os.c
  2769. --- ./inadyn-1.99.15/src/os.c   2016-01-22 13:41:48.000000000 +0300
  2770. +++ ./inadyn_padavan/src/os.c   2016-01-22 14:22:01.000000000 +0300
  2771. @@ -219,6 +219,7 @@
  2772.                 break;
  2773.  
  2774.         default:                /* parent */
  2775. +               waitpid(child, NULL, 0);
  2776.                 break;
  2777.         }
  2778.  
  2779. @@ -472,8 +473,8 @@
  2780.                 return RC_FILE_IO_ACCESS_ERROR;
  2781.         }
  2782.  
  2783. -       if (old_pidfile(pidfile_path))
  2784. -               logit(LOG_WARNING, "Failed creating pidfile %s: %m", pidfile_path);
  2785. +       /* Not creating a pidfile is OK, the cache file is the critical point. */
  2786. +       old_pidfile(pidfile_path);
  2787.  
  2788.         return 0;
  2789.  }
  2790. diff -urN ./inadyn-1.99.15/src/plugin.c ./inadyn_padavan/src/plugin.c
  2791. --- ./inadyn-1.99.15/src/plugin.c       2016-01-22 13:41:47.000000000 +0300
  2792. +++ ./inadyn_padavan/src/plugin.c       2016-01-22 14:22:01.000000000 +0300
  2793. @@ -21,7 +21,6 @@
  2794.   * THE SOFTWARE.
  2795.   */
  2796.  
  2797. -#include "config.h"
  2798.  #include <errno.h>
  2799.  #include <dlfcn.h>             /* dlopen() et al */
  2800.  #include <dirent.h>            /* readdir() et al */
  2801. @@ -139,7 +138,8 @@
  2802.  }
  2803.  
  2804.  /* Private daemon API *******************************************************/
  2805. -#if o
  2806. +
  2807. +#if 0
  2808.  /**
  2809.   * load_one - Load one plugin
  2810.   * @path: Path to finit plugins, usually %PLUGIN_PATH
  2811. diff -urN ./inadyn-1.99.15/src/ssl.c ./inadyn_padavan/src/ssl.c
  2812. --- ./inadyn-1.99.15/src/ssl.c  2016-01-22 13:41:48.000000000 +0300
  2813. +++ ./inadyn_padavan/src/ssl.c  2016-01-22 14:22:01.000000000 +0300
  2814. @@ -1,6 +1,6 @@
  2815.  /* Interface for optional HTTPS functions
  2816.   *
  2817. - * Copyright (C) 2014  Joachim Nilsson <troglobit@gmail.com>
  2818. + * Copyright (C) 2014-2015  Joachim Nilsson <troglobit@gmail.com>
  2819.   *
  2820.   * This program is free software; you can redistribute it and/or
  2821.   * modify it under the terms of the GNU General Public License
  2822. @@ -20,8 +20,7 @@
  2823.   */
  2824.  
  2825.  #include "debug.h"
  2826. -#include "http.h"
  2827. -
  2828. +#include "ssl.h"
  2829.  
  2830.  #ifdef ENABLE_SSL
  2831.  /* SSL SNI support: tell the servername we want to speak to */
  2832. @@ -32,9 +31,6 @@
  2833.  #if defined(CONFIG_OPENSSL)
  2834.         /* api returns 1 for success */
  2835.         rc = !SSL_set_tlsext_host_name(ssl, sn);
  2836. -#elif defined(CONFIG_GNUTLS)
  2837. -       /* api returns 0 for success */
  2838. -       rc = gnutls_server_name_set(ssl->gnutls_state, GNUTLS_NAME_DNS, sn, strlen(sn));
  2839.  #endif
  2840.  
  2841.         return rc;
  2842. @@ -48,59 +44,77 @@
  2843.         (void)msg;
  2844.         return 0;
  2845.  #else
  2846. +       int err, err_ssl, rc = 0;
  2847.         char buf[256];
  2848.         const char *sn;
  2849. -#ifdef CONFIG_GNUTLS
  2850. -       const
  2851. -#endif
  2852. -               X509 *cert;
  2853. +       X509 *cert;
  2854.  
  2855. -       logit(LOG_INFO, "%s, initiating HTTPS ...", msg);
  2856. +       if (client->verbose > 1)
  2857. +               logit(LOG_INFO, "%s, initiating HTTPS ...", msg);
  2858.  
  2859. -       client->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
  2860. -       if (!client->ssl_ctx)
  2861. -               return RC_HTTPS_OUT_OF_MEMORY;
  2862. +       do {
  2863. +               client->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
  2864. +               if (!client->ssl_ctx)
  2865. +                       return RC_HTTPS_OUT_OF_MEMORY;
  2866.  
  2867.  #if defined(CONFIG_OPENSSL)
  2868. -       /* POODLE, only allow TLSv1.x or later */
  2869. -       SSL_CTX_set_options(client->ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
  2870. -#else
  2871. -       /* GnuTLS already defaults to TLS 1.x */
  2872. -#endif
  2873. -
  2874. -       client->ssl = SSL_new(client->ssl_ctx);
  2875. -       if (!client->ssl)
  2876. -               return RC_HTTPS_OUT_OF_MEMORY;
  2877. -
  2878. -#ifdef SSL_MODE_SEND_FALLBACK_SCSV
  2879. -       SSL_set_mode(client->ssl, SSL_MODE_SEND_FALLBACK_SCSV);
  2880. +               /* POODLE, only allow TLSv1.x or later */
  2881. +               SSL_CTX_set_options(client->ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION);
  2882.  #endif
  2883.  
  2884. -       http_get_remote_name(client, &sn);
  2885. -       if (set_server_name(client->ssl, sn))
  2886. -               return RC_HTTPS_SNI_ERROR;
  2887. -
  2888. -       SSL_set_fd(client->ssl, client->tcp.ip.socket);
  2889. -       if (-1 == SSL_connect(client->ssl))
  2890. -               return RC_HTTPS_FAILED_CONNECT;
  2891. -
  2892. -       logit(LOG_INFO, "SSL connection using %s", SSL_get_cipher(client->ssl));
  2893. -
  2894. -       /* Get server's certificate (note: beware of dynamic allocation) - opt */
  2895. -       cert = SSL_get_peer_certificate(client->ssl);
  2896. -       if (!cert)
  2897. -               return RC_HTTPS_FAILED_GETTING_CERT;
  2898. -
  2899. -       /* Logging some cert details. Please note: X509_NAME_oneline doesn't
  2900. -          work when giving NULL instead of a buffer. */
  2901. -       X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));
  2902. -       logit(LOG_INFO, "SSL server cert subject: %s", buf);
  2903. -       X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
  2904. -       logit(LOG_INFO, "SSL server cert issuer: %s", buf);
  2905. -
  2906. -       /* We could do all sorts of certificate verification stuff here before
  2907. -          deallocating the certificate. */
  2908. -       X509_free(cert);
  2909. +               client->ssl = SSL_new(client->ssl_ctx);
  2910. +               if (!client->ssl) {
  2911. +                       rc = RC_HTTPS_OUT_OF_MEMORY;
  2912. +                       break;
  2913. +               }
  2914. +
  2915. +               http_get_remote_name(client, &sn);
  2916. +               if (set_server_name(client->ssl, sn)) {
  2917. +                       rc = RC_HTTPS_SNI_ERROR;
  2918. +                       break;
  2919. +               }
  2920. +
  2921. +               SSL_set_fd(client->ssl, client->tcp.ip.socket);
  2922. +               err = SSL_connect(client->ssl);
  2923. +               if (err <= 0) {
  2924. +                       err_ssl = SSL_get_error(client->ssl, err);
  2925. +                       logit(LOG_ERR, "SSL_connect %s! (err: %d)", "FAILED", err_ssl);
  2926. +                       rc = RC_HTTPS_FAILED_CONNECT;
  2927. +                       break;
  2928. +               }
  2929. +
  2930. +               if (client->verbose > 0)
  2931. +                       logit(LOG_INFO, "SSL connection using %s", SSL_get_cipher(client->ssl));
  2932. +
  2933. +               /* Get server's certificate (note: beware of dynamic allocation) - opt */
  2934. +               cert = SSL_get_peer_certificate(client->ssl);
  2935. +               if (!cert) {
  2936. +                       logit(LOG_ERR, "SSL_get_peer_certificate %s!", "FAILED");
  2937. +                       rc = RC_HTTPS_FAILED_GETTING_CERT;
  2938. +                       break;
  2939. +               }
  2940. +
  2941. +               /* Logging some cert details. Please note: X509_NAME_oneline doesn't
  2942. +                  work when giving NULL instead of a buffer. */
  2943. +               buf[0] = 0;
  2944. +               X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));
  2945. +               if (client->verbose > 1)
  2946. +                       logit(LOG_INFO, "SSL server cert subject: %s", buf);
  2947. +
  2948. +               buf[0] = 0;
  2949. +               X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
  2950. +               if (client->verbose > 1)
  2951. +                       logit(LOG_INFO, "SSL server cert issuer: %s", buf);
  2952. +
  2953. +               /* We could do all sorts of certificate verification stuff here before
  2954. +                  deallocating the certificate. */
  2955. +               X509_free(cert);
  2956. +       } while (0);
  2957. +
  2958. +       if (rc) {
  2959. +               ssl_exit(client);
  2960. +               return rc;
  2961. +       }
  2962.  
  2963.         return 0;
  2964.  #endif
  2965. @@ -112,17 +126,93 @@
  2966.         (void)client;
  2967.         return 0;
  2968.  #else
  2969. -       /* SSL/TLS close_notify */
  2970. -       SSL_shutdown(client->ssl);
  2971. -
  2972. -       /* Clean up. */
  2973. -       SSL_free(client->ssl);
  2974. -       SSL_CTX_free(client->ssl_ctx);
  2975. +       if (client->ssl) {
  2976. +               /* SSL/TLS close_notify */
  2977. +               SSL_shutdown(client->ssl);
  2978. +
  2979. +               /* Clean up. */
  2980. +               SSL_free(client->ssl);
  2981. +               client->ssl = NULL;
  2982. +       }
  2983. +
  2984. +       if (client->ssl_ctx) {
  2985. +               /* Clean up. */
  2986. +               SSL_CTX_free(client->ssl_ctx);
  2987. +               client->ssl_ctx = NULL;
  2988. +       }
  2989.  
  2990.         return 0;
  2991.  #endif
  2992.  }
  2993.  
  2994. +#ifdef ENABLE_SSL
  2995. +static ssize_t
  2996. +ssl_read_socket(SSL* ssl, char *buf, size_t len)
  2997. +{
  2998. +       int nr, err;
  2999. +       size_t total = 0;
  3000. +
  3001. +       do {
  3002. +               nr = SSL_read(ssl, buf + total, len - total);
  3003. +               if (nr > 0) {
  3004. +                       total += (size_t)nr;
  3005. +               } else {
  3006. +                       err = SSL_get_error(ssl, nr);
  3007. +                       switch (err) {
  3008. +                       case SSL_ERROR_ZERO_RETURN:
  3009. +                               goto read_out;
  3010. +                               break;
  3011. +                       case SSL_ERROR_WANT_WRITE:
  3012. +                       case SSL_ERROR_WANT_READ:
  3013. +                               break;
  3014. +                       default:
  3015. +                               if (total == 0)
  3016. +                                       total = (ssize_t)-1;
  3017. +                               logit(LOG_ERR, "SSL_read %s! (err: %d)", "FAILED", err);
  3018. +                               goto read_out;
  3019. +                       }
  3020. +               }
  3021. +       } while ((total < len) && SSL_pending(ssl));
  3022. +
  3023. +read_out:
  3024. +
  3025. +       return (ssize_t)total;
  3026. +}
  3027. +
  3028. +static ssize_t
  3029. +ssl_write_socket(SSL* ssl, const char *buf, size_t len)
  3030. +{
  3031. +       int nw, err;
  3032. +       size_t total = 0;
  3033. +
  3034. +       while (total < len) {
  3035. +               nw = SSL_write(ssl, buf + total, len - total);
  3036. +               if (nw > 0) {
  3037. +                       total += (size_t)nw;
  3038. +               } else {
  3039. +                       err = SSL_get_error(ssl, nw);
  3040. +                       switch (err) {
  3041. +                       case SSL_ERROR_ZERO_RETURN:
  3042. +                               goto write_out;
  3043. +                               break;
  3044. +                       case SSL_ERROR_WANT_WRITE:
  3045. +                       case SSL_ERROR_WANT_READ:
  3046. +                               break;
  3047. +                       default:
  3048. +                               if (total == 0)
  3049. +                                       total = (ssize_t)-1;
  3050. +                               logit(LOG_ERR, "SSL_write %s! (err: %d)", "FAILED", err);
  3051. +                               goto write_out;
  3052. +                       }
  3053. +               }
  3054. +       }
  3055. +
  3056. +write_out:
  3057. +
  3058. +       return (ssize_t)total;
  3059. +}
  3060. +#endif
  3061. +
  3062.  int ssl_send(http_t *client, const char *buf, int len)
  3063.  {
  3064.  #ifndef ENABLE_SSL
  3065. @@ -131,13 +221,15 @@
  3066.         (void)len;
  3067.         return RC_HTTPS_NO_SSL_SUPPORT;
  3068.  #else
  3069. -       int err = SSL_write(client->ssl, buf, len);
  3070. +       ssize_t nw;
  3071.  
  3072. -       if (err <= 0)
  3073. -               /* XXX: TODO add SSL_get_error() to figure out why */
  3074. +       nw = ssl_write_socket(client->ssl, buf, len);
  3075. +       if (nw <= 0)
  3076.                 return RC_HTTPS_SEND_ERROR;
  3077.  
  3078. -       logit(LOG_DEBUG, "Successfully sent DDNS update using HTTPS!");
  3079. +       if (client->verbose > 1)
  3080. +               logit(LOG_DEBUG, "Successfully sent DDNS update using HTTPS!");
  3081. +
  3082.         return 0;
  3083.  #endif
  3084.  }
  3085. @@ -151,20 +243,28 @@
  3086.         (void)recv_len;
  3087.         return RC_HTTPS_NO_SSL_SUPPORT;
  3088.  #else
  3089. -       int len, err;
  3090. +       ssize_t nr;
  3091.  
  3092. -       /* Read HTTP header */
  3093. -       len = err = SSL_read(client->ssl, buf, buf_len);
  3094. -       if (err <= 0)
  3095. -               /* XXX: TODO add SSL_get_error() to figure out why */
  3096. +       /* Read HTTP header & body */
  3097. +       nr = ssl_read_socket(client->ssl, buf, buf_len);
  3098. +       if (nr <= 0) {
  3099. +               *recv_len = 0;
  3100.                 return RC_HTTPS_RECV_ERROR;
  3101. +       }
  3102. +
  3103. +       *recv_len = nr;
  3104.  
  3105.         /* Read HTTP body */
  3106. -       *recv_len = SSL_read(client->ssl, &buf[len], buf_len - len);
  3107. -       if (*recv_len <= 0)
  3108. -               *recv_len = 0;
  3109. -       *recv_len += len;
  3110. -       logit(LOG_DEBUG, "Successfully received DDNS update response (%d bytes) using HTTPS!", *recv_len);
  3111. +       buf_len -= nr;
  3112. +       if (buf_len > 0) {
  3113. +               buf += nr;
  3114. +               nr = ssl_read_socket(client->ssl, buf, buf_len);
  3115. +               if (nr > 0)
  3116. +                       *recv_len += nr;
  3117. +       }
  3118. +
  3119. +       if (client->verbose > 1)
  3120. +               logit(LOG_DEBUG, "Successfully received DDNS update response (%d bytes) using HTTPS!", *recv_len);
  3121.  
  3122.         return 0;
  3123.  #endif
  3124. diff -urN ./inadyn-1.99.15/src/tcp.c ./inadyn_padavan/src/tcp.c
  3125. --- ./inadyn-1.99.15/src/tcp.c  2016-01-22 13:41:47.000000000 +0300
  3126. +++ ./inadyn_padavan/src/tcp.c  2016-01-22 14:22:01.000000000 +0300
  3127. @@ -96,7 +96,7 @@
  3128.  }
  3129.  
  3130.  /* On error tcp_exit() is called by upper layers. */
  3131. -int tcp_init(tcp_sock_t *tcp, char *msg)
  3132. +int tcp_init(tcp_sock_t *tcp, char *msg, int verbose)
  3133.  {
  3134.         int rc = 0;
  3135.         char host[NI_MAXHOST];
  3136. @@ -138,15 +138,15 @@
  3137.                 /* Attempt to set TCP timers, silently fall back to OS defaults */
  3138.                 sv.tv_sec  =  tcp->ip.timeout / 1000;
  3139.                 sv.tv_usec = (tcp->ip.timeout % 1000) * 1000;
  3140. -               if (-1 == setsockopt(tcp->ip.socket, SOL_SOCKET, SO_RCVTIMEO, &sv, sizeof(sv)))
  3141. -                       logit(LOG_WARNING, "Failed setting receive timeout socket option: %m");
  3142. -               if (-1 == setsockopt(tcp->ip.socket, SOL_SOCKET, SO_SNDTIMEO, &sv, sizeof(sv)))
  3143. -                       logit(LOG_WARNING, "Failed setting send timeout socket option: %m");
  3144. +               setsockopt(tcp->ip.socket, SOL_SOCKET, SO_RCVTIMEO, &sv, sizeof(sv));
  3145. +               setsockopt(tcp->ip.socket, SOL_SOCKET, SO_SNDTIMEO, &sv, sizeof(sv));
  3146.  
  3147.                 sa    = tcp->ip.remote_addr;
  3148.                 salen = tcp->ip.remote_len;
  3149. -               if (!getnameinfo(&sa, salen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST))
  3150. -                       logit(LOG_INFO, "%s, connecting to %s(%s:%d)", msg, tcp->ip.p_remote_host_name, host, tcp->ip.port);
  3151. +               if (!getnameinfo(&sa, salen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) {
  3152. +                       if (verbose > 0)
  3153. +                               logit(LOG_INFO, "%s, connecting to %s (%s:%d)", msg, tcp->ip.p_remote_host_name, host, tcp->ip.port);
  3154. +               }
  3155.                 else
  3156.                         logit(LOG_ERR, "%s, failed resolving %s!", msg, host);
  3157.  
  3158. ryzhovau@ryzhov4:~/temp$
Add Comment
Please, Sign In to add comment