1
0

patch-ez-ipupdate_c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. $Id$
  2. cjb.net support by <tg@freewrt.org>
  3. --- ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c Mon Mar 11 23:31:25 2002
  4. +++ ez-ipupdate-3.0.11b8/ez-ipupdate.c Tue Jul 31 14:05:00 2007
  5. @@ -87,6 +87,10 @@
  6. #define JUSTL_REQUEST "/bin/controlpanel/dyndns/jlc.pl"
  7. #define JUSTL_VERSION "2.0"
  8. +#define CJB_DEFAULT_SERVER "www.cjb.net"
  9. +#define CJB_DEFAULT_PORT "80"
  10. +#define CJB_REQUEST "/cgi-bin/dynip.cgi"
  11. +
  12. #define DYNS_DEFAULT_SERVER "www.dyns.cx"
  13. #define DYNS_DEFAULT_PORT "80"
  14. #define DYNS_REQUEST "/postscript.php"
  15. @@ -139,6 +143,9 @@
  16. #if HAVE_SIGNAL_H
  17. # include <signal.h>
  18. #endif
  19. +#if HAVE_TIME_H
  20. +# include <time.h>
  21. +#endif
  22. #if HAVE_SYS_TIME_H
  23. # include <sys/time.h>
  24. #endif
  25. @@ -165,7 +172,7 @@
  26. #endif
  27. -#if __linux__ || __SVR4 || __OpenBSD__ || __FreeBSD__ || __NetBSD__
  28. +#if __GLIBC__ || __SVR4 || __OpenBSD__ || __FreeBSD__ || __NetBSD__
  29. # define IF_LOOKUP 1
  30. # include <sys/ioctl.h>
  31. # include <net/if.h>
  32. @@ -325,6 +332,10 @@ int JUSTL_update_entry(void);
  33. int JUSTL_check_info(void);
  34. static char *JUSTL_fields_used[] = { "server", "user", "host", NULL };
  35. +int CJB_update_entry(void);
  36. +int CJB_check_info(void);
  37. +static char *CJB_fields_used[] = { "server", "user", NULL };
  38. +
  39. int DYNS_update_entry(void);
  40. int DYNS_check_info(void);
  41. static char *DYNS_fields_used[] = { "server", "user", "host", NULL };
  42. @@ -474,6 +485,16 @@ struct service_t services[] = {
  43. JUSTL_DEFAULT_PORT,
  44. JUSTL_REQUEST
  45. },
  46. + { "cjb.net",
  47. + { "cjb", 0, 0, },
  48. + NULL,
  49. + CJB_update_entry,
  50. + CJB_check_info,
  51. + CJB_fields_used,
  52. + CJB_DEFAULT_SERVER,
  53. + CJB_DEFAULT_PORT,
  54. + CJB_REQUEST
  55. + },
  56. { "dyns",
  57. { "dyns", 0, 0, },
  58. NULL,
  59. @@ -640,7 +661,7 @@ void print_usage( void )
  60. fprintf(stdout, " -q, --quiet \t\t\tbe quiet\n");
  61. fprintf(stdout, " -r, --retrys <num>\t\tnumber of trys (default: 1)\n");
  62. fprintf(stdout, " -R, --run-as-user <user>\tchange to <user> for running, be ware\n\t\t\t\tthat this can cause problems with handeling\n\t\t\t\tSIGHUP properly if that user can't read the\n\t\t\t\tconfig file. also it can't write it's pid file \n\t\t\t\tto a root directory\n");
  63. - fprintf(stdout, " -Q, --run-as-euser <user>\tchange to effective <user> for running, \n\t\t\t\tthis is NOT secure but it does solve the \n\t\t\t\tproblems with run-as-user and config files and \n\t\t\t\tpid files.\n");
  64. + fprintf(stdout, " -Q, --run-as-euser <user>\tchange to effective <user> for running, \n\t\t\t\tthis is NOT secure but it does solve the \n\t\t\t\tproblems with run-as-user and config files and \n\t\t\t\tpid files\n");
  65. fprintf(stdout, " -s, --server <server[:port]>\tthe server to connect to\n");
  66. fprintf(stdout, " -S, --service-type <server>\tthe type of service that you are using\n");
  67. width = fprintf(stdout, "\t\t\t\ttry one of: ") + 4*7;
  68. @@ -682,7 +703,7 @@ void print_credits( void )
  69. void print_signalhelp( void )
  70. {
  71. - fprintf(stdout, "\nsignals are only really used when in daemon mode.\n\n");
  72. + fprintf(stdout, "\nsignals are only really used when in daemon mode\n\n");
  73. fprintf(stdout, "signals: \n");
  74. fprintf(stdout, " HUP\t\tcauses it to re-read its config file\n");
  75. fprintf(stdout, " TERM\t\twake up and possibly perform an update\n");
  76. @@ -693,7 +714,7 @@ void print_signalhelp( void )
  77. #if HAVE_SIGNAL_H
  78. RETSIGTYPE sigint_handler(int sig)
  79. {
  80. - char message[] = "interupted.\n";
  81. + char message[] = "interrupted\n";
  82. close(client_sockfd);
  83. write(2, message, sizeof(message)-1);
  84. @@ -704,6 +725,10 @@ RETSIGTYPE sigint_handler(int sig)
  85. }
  86. #endif
  87. +#if HAVE_SYSLOG_H
  88. + closelog();
  89. +#endif
  90. +
  91. exit(1);
  92. }
  93. RETSIGTYPE generic_sig_handler(int sig)
  94. @@ -798,7 +823,7 @@ void show_message(char *fmt, ...)
  95. sprintf(buf, "message incomplete because your OS sucks: %s\n", fmt);
  96. #endif
  97. - syslog(LOG_NOTICE, buf);
  98. + syslog(LOG_NOTICE, "%s", buf);
  99. }
  100. else
  101. {
  102. @@ -1439,7 +1464,7 @@ int do_connect(int *sock, char *host, ch
  103. if(!(options & OPT_QUIET))
  104. {
  105. fprintf(stderr,
  106. - "connected to %s (%s) on port %d.\n",
  107. + "connected to %s (%s) on port %d\n",
  108. host,
  109. inet_ntoa(address.sin_addr),
  110. ntohs(address.sin_port));
  111. @@ -1683,7 +1708,7 @@ static int ODS_read_response(char *buf,
  112. close(client_sockfd);
  113. return(-1);
  114. }
  115. - if(strstr(buf, "\r\n") > 0)
  116. + if(strstr(buf, "\n") != NULL)
  117. {
  118. break;
  119. }
  120. @@ -1702,8 +1727,8 @@ int NULL_check_info(void)
  121. if(options & OPT_DAEMON)
  122. {
  123. - fprintf(stderr, "no compile time default service was set therefor you must "
  124. - "specify a service type.\n");
  125. + fprintf(stderr, "no compile time default service was set, you must "
  126. + "specify a service type\n");
  127. return(-1);
  128. }
  129. @@ -2039,7 +2064,7 @@ int DYNDNS_update_entry(void)
  130. }
  131. else if(strstr(buf, "\nnumhost") != NULL)
  132. {
  133. - show_message("Too many or too few hosts found\n");
  134. + show_message("too many or too few hosts found\n");
  135. retval = UPDATERES_SHUTDOWN;
  136. }
  137. else if(strstr(buf, "\ndnserr") != NULL)
  138. @@ -2051,17 +2076,17 @@ int DYNDNS_update_entry(void)
  139. }
  140. else if(strstr(buf, "\n911") != NULL)
  141. {
  142. - show_message("Ahhhh! call 911!\n");
  143. + show_message("ahhhh! call 911!\n");
  144. retval = UPDATERES_SHUTDOWN;
  145. }
  146. else if(strstr(buf, "\n999") != NULL)
  147. {
  148. - show_message("Ahhhh! call 999!\n");
  149. + show_message("ahhhh! call 999!\n");
  150. retval = UPDATERES_SHUTDOWN;
  151. }
  152. else if(strstr(buf, "\n!donator") != NULL)
  153. {
  154. - show_message("a feature requested is only available to donators, please donate.\n", host);
  155. + show_message("a feature requested is only available to donators, please donate\n", host);
  156. retval = UPDATERES_OK;
  157. }
  158. // this one should be last as it is a stupid string to signify waits
  159. @@ -2095,9 +2120,9 @@ int DYNDNS_update_entry(void)
  160. sprintf(reason, "problem parsing reason for wait response");
  161. }
  162. - show_message("Wait response received, waiting for %s before next update.\n",
  163. + show_message("wait response received, waiting for %s before next update\n",
  164. format_time(howlong));
  165. - show_message("Wait response reason: %d\n", N_STR(reason));
  166. + show_message("wait response reason: %d\n", N_STR(reason));
  167. sleep(howlong);
  168. retval = UPDATERES_ERROR;
  169. }
  170. @@ -3370,7 +3395,7 @@ int GNUDIP_check_info(void)
  171. {
  172. if(!(options & OPT_QUIET))
  173. {
  174. - fprintf(stderr, "warning: for GNUDIP the \"address\" parpameter is only used if set to \"0.0.0.0\" thus making an offline request.\n");
  175. + fprintf(stderr, "warning: for GNUDIP the \"address\" parameter is only used if set to \"0.0.0.0\" thus making an offline request\n");
  176. }
  177. }
  178. @@ -3392,7 +3417,7 @@ int GNUDIP_update_entry(void)
  179. // send an offline request if address 0.0.0.0 is used
  180. // otherwise, we ignore the address and send an update request
  181. - gnudip_request[0] = strcmp(address, "0.0.0.0") == 0 ? '1' : '0';
  182. + gnudip_request[0] = address && strcmp(address, "0.0.0.0") == 0 ? '1' : '0';
  183. gnudip_request[1] = '\0';
  184. // find domainname
  185. @@ -3660,6 +3685,140 @@ int JUSTL_update_entry(void)
  186. return(UPDATERES_OK);
  187. }
  188. +int CJB_check_info(void)
  189. +{
  190. + char buf[BUFSIZ+1];
  191. +
  192. + if(interface == NULL && address == NULL)
  193. + {
  194. + if(options & OPT_DAEMON)
  195. + {
  196. + fprintf(stderr, "you must provide either an interface or an address\n");
  197. + return(-1);
  198. + }
  199. + if(interface) { free(interface); }
  200. + printf("interface: ");
  201. + *buf = '\0';
  202. + fgets(buf, BUFSIZ, stdin);
  203. + chomp(buf);
  204. + option_handler(CMD_interface, buf);
  205. + }
  206. +
  207. + warn_fields(service->fields_used);
  208. +
  209. + return 0;
  210. +}
  211. +
  212. +int CJB_update_entry(void)
  213. +{
  214. + char buf[BUFFER_SIZE+1];
  215. + char *bp = buf;
  216. + int bytes;
  217. + int btot;
  218. + int ret;
  219. +
  220. + buf[BUFFER_SIZE] = '\0';
  221. +
  222. + if(do_connect((int*)&client_sockfd, server, port) != 0)
  223. + {
  224. + if(!(options & OPT_QUIET))
  225. + {
  226. + show_message("error connecting to %s:%s\n", server, port);
  227. + }
  228. + return(UPDATERES_ERROR);
  229. + }
  230. +
  231. + snprintf(buf, BUFFER_SIZE, "GET %s?", request);
  232. + output(buf);
  233. + snprintf(buf, BUFFER_SIZE, "%s=%s&", "username", user_name);
  234. + output(buf);
  235. + snprintf(buf, BUFFER_SIZE, "%s=%s", "password", password);
  236. + output(buf);
  237. +#if 0
  238. + /* cjb does IP address autodetection */
  239. + snprintf(buf, BUFFER_SIZE, "&%s=%s", "ip", address);
  240. + output(buf);
  241. +#endif
  242. + snprintf(buf, BUFFER_SIZE, " HTTP/1.0\015\012");
  243. + output(buf);
  244. + snprintf(buf, BUFFER_SIZE, "User-Agent: %s-%s %s [%s] (%s)\015\012",
  245. + "ez-update", VERSION, OS, (options & OPT_DAEMON) ? "daemon" : "", "by OpenADK");
  246. + output(buf);
  247. + snprintf(buf, BUFFER_SIZE, "\015\012");
  248. + output(buf);
  249. +
  250. + bp = buf;
  251. + bytes = 0;
  252. + btot = 0;
  253. + while((bytes=read_input(bp, BUFFER_SIZE-btot)) > 0)
  254. + {
  255. + bp += bytes;
  256. + btot += bytes;
  257. + dprintf((stderr, "btot: %d\n", btot));
  258. + }
  259. + close(client_sockfd);
  260. + buf[btot] = '\0';
  261. +
  262. + dprintf((stderr, "server output: %s\n", buf));
  263. +
  264. + if(sscanf(buf, " HTTP/1.%*c %3d", &ret) != 1)
  265. + {
  266. + ret = -1;
  267. + }
  268. +
  269. + switch(ret)
  270. + {
  271. + case -1:
  272. + if(!(options & OPT_QUIET))
  273. + {
  274. + show_message("strange server response, are you connecting to the right server?\n");
  275. + }
  276. + return(UPDATERES_ERROR);
  277. + break;
  278. +
  279. + case 200:
  280. + if(strstr(buf, " updated ") != NULL)
  281. + {
  282. + if(!(options & OPT_QUIET))
  283. + {
  284. + printf("request successful\n");
  285. + }
  286. + }
  287. + else
  288. + {
  289. + show_message("error processing request\n");
  290. + if(!(options & OPT_QUIET))
  291. + {
  292. + fprintf(stderr, "server output: %s\n", buf);
  293. + }
  294. + return(UPDATERES_ERROR);
  295. + }
  296. + break;
  297. +
  298. + case 401:
  299. + if(!(options & OPT_QUIET))
  300. + {
  301. + show_message("authentication failure\n");
  302. + }
  303. + return(UPDATERES_SHUTDOWN);
  304. + break;
  305. +
  306. + default:
  307. + if(!(options & OPT_QUIET))
  308. + {
  309. + // reuse the auth buffer
  310. + *auth = '\0';
  311. + sscanf(buf, " HTTP/1.%*c %*3d %255[^\r\n]", auth);
  312. + show_message("unknown return code: %d\n", ret);
  313. + show_message("server response: %s\n", auth);
  314. + }
  315. + return(UPDATERES_ERROR);
  316. + break;
  317. + }
  318. +
  319. + return(UPDATERES_OK);
  320. +}
  321. +
  322. int DYNS_check_info(void)
  323. {
  324. char buf[BUFSIZ+1];
  325. @@ -3943,22 +4102,22 @@ int HN_update_entry(void)
  326. break;
  327. case 201:
  328. - show_message("Last update was less than %d seconds ago.\n", 300);
  329. + show_message("last update was less than %d seconds ago\n", 300);
  330. return(UPDATERES_ERROR);
  331. break;
  332. case 202:
  333. - show_message("Server error.\n");
  334. + show_message("server error\n");
  335. return(UPDATERES_ERROR);
  336. break;
  337. case 203:
  338. - show_message("Failure because account is frozen (by admin).\n");
  339. + show_message("failure because account is frozen (by admin)\n");
  340. return(UPDATERES_SHUTDOWN);
  341. break;
  342. case 204:
  343. - show_message("Failure because account is locked (by user).\n");
  344. + show_message("failure because account is locked (by user)\n");
  345. return(UPDATERES_SHUTDOWN);
  346. break;
  347. @@ -4215,8 +4374,6 @@ int HEIPV6TB_update_entry(void)
  348. switch(ret)
  349. {
  350. - char *p;
  351. -
  352. case -1:
  353. if(!(options & OPT_QUIET))
  354. {
  355. @@ -4349,7 +4506,7 @@ void handle_sig(int sig)
  356. case SIGHUP:
  357. if(config_file)
  358. {
  359. - show_message("SIGHUP recieved, re-reading config file\n");
  360. + show_message("SIGHUP received, re-reading config file\n");
  361. if(parse_conf_file(config_file, conf_commands) != 0)
  362. {
  363. show_message("error parsing config file \"%s\"\n", config_file);
  364. @@ -4384,6 +4541,7 @@ void handle_sig(int sig)
  365. int main(int argc, char **argv)
  366. {
  367. + char *tmp;
  368. int ifresolve_warned = 0;
  369. int i;
  370. int retval = 1;
  371. @@ -4395,9 +4553,10 @@ int main(int argc, char **argv)
  372. mcheck(NULL);
  373. #endif
  374. - dprintf((stderr, "staring...\n"));
  375. + dprintf((stderr, "starting...\n"));
  376. - program_name = argv[0];
  377. + tmp = strrchr(argv[0], '/');
  378. + program_name = tmp ? tmp + 1 : argv[0];
  379. options = 0;
  380. *user = '\0';
  381. timeout.tv_sec = DEFAULT_TIMEOUT;
  382. @@ -4417,7 +4576,7 @@ int main(int argc, char **argv)
  383. if(!(options & OPT_QUIET) && !(options & OPT_DAEMON))
  384. {
  385. - fprintf(stderr, "ez-ipupdate Version %s\nCopyright (C) 1998-2001 Angus Mackay.\n", VERSION);
  386. + fprintf(stderr, "%s Version %s\nCopyright (C) 1998-2001 Angus Mackay\n", program_name, VERSION);
  387. }
  388. dprintf((stderr, "options: 0x%04X\n", options));
  389. @@ -4434,7 +4593,7 @@ int main(int argc, char **argv)
  390. {
  391. if(service->check_info() != 0)
  392. {
  393. - fprintf(stderr, "invalid data to perform requested action.\n");
  394. + fprintf(stderr, "invalid data to perform requested action\n");
  395. exit(1);
  396. }
  397. }
  398. @@ -4456,13 +4615,13 @@ int main(int argc, char **argv)
  399. dprintf((stderr, "user_name: %s\n", user_name));
  400. dprintf((stderr, "password: %s\n", password));
  401. }
  402. - if(*user_name == '\0')
  403. + if(*user_name == '\0' && !(options & OPT_DAEMON))
  404. {
  405. printf("user name: ");
  406. fgets(user_name, sizeof(user_name), stdin);
  407. chomp(user_name);
  408. }
  409. - if(*password == '\0')
  410. + if(*password == '\0' && !(options & OPT_DAEMON))
  411. {
  412. strncpy(password, getpass("password: "), sizeof(password));
  413. }
  414. @@ -4480,7 +4639,7 @@ int main(int argc, char **argv)
  415. if(service->check_info() != 0)
  416. {
  417. - fprintf(stderr, "invalid data to perform requested action.\n");
  418. + fprintf(stderr, "invalid data to perform requested action\n");
  419. exit(1);
  420. }
  421. @@ -4503,7 +4662,7 @@ int main(int argc, char **argv)
  422. if(interface == NULL)
  423. {
  424. - fprintf(stderr, "invalid data to perform requested action.\n");
  425. + fprintf(stderr, "invalid data to perform requested action\n");
  426. fprintf(stderr, "you must provide an interface for daemon mode");
  427. exit(1);
  428. }
  429. @@ -4519,23 +4678,25 @@ int main(int argc, char **argv)
  430. if(fork() > 0) { exit(0); } /* parent */
  431. }
  432. +# if HAVE_SYSLOG_H
  433. + openlog(program_name, LOG_PID, LOG_DAEMON );
  434. + //options |= OPT_QUIET;
  435. +# endif
  436. + show_message("version %s, interface %s, host %s, server %s, service %s\n",
  437. + VERSION, N_STR(interface), N_STR(host), server, service->title);
  438. +
  439. #if HAVE_GETPID
  440. if(pid_file && pid_file_create(pid_file) != 0)
  441. {
  442. - fprintf(stderr, "exiting...\n");
  443. + show_message("could not create pid file %s (%s), exiting\n",
  444. + pid_file, strerror(errno));
  445. +#if HAVE_SYSLOG_H
  446. + closelog();
  447. +#endif
  448. exit(1);
  449. }
  450. #endif
  451. -# if HAVE_SYSLOG_H
  452. - openlog(program_name, LOG_PID, LOG_USER );
  453. - options |= OPT_QUIET;
  454. -# endif
  455. - show_message("ez-ipupdate Version %s, Copyright (C) 1998-2001 Angus Mackay.\n",
  456. - VERSION);
  457. - show_message("%s started for interface %s host %s using server %s and service %s\n",
  458. - program_name, N_STR(interface), N_STR(host), server, service->title);
  459. -
  460. memset(&sin, 0, sizeof(sin));
  461. if(cache_file)
  462. @@ -4560,7 +4721,7 @@ int main(int argc, char **argv)
  463. strftime(timebuf, sizeof(timebuf), "%Y/%m/%d %H:%M", ts);
  464. show_message("got last update %s on %s from cache file\n", ipstr, timebuf);
  465. }
  466. - else
  467. + else if(ipstr||ipdate)
  468. {
  469. show_message("malformed cache file: %s\n", cache_file);
  470. }
  471. @@ -4647,7 +4808,7 @@ int main(int argc, char **argv)
  472. }
  473. else
  474. {
  475. - show_message("failure to update %s->%s (%s)\n",
  476. + show_message("failed to update %s->%s (%s)\n",
  477. interface, inet_ntoa(sin.sin_addr), N_STR(host));
  478. memset(&sin, 0, sizeof(sin));
  479. @@ -4671,7 +4832,7 @@ int main(int argc, char **argv)
  480. dprintf((stderr, "updateres: %d\n", updateres));
  481. if(updateres == UPDATERES_SHUTDOWN)
  482. {
  483. - show_message("shuting down updater for %s due to fatal error\n",
  484. + show_message("shutting down updater for %s due to fatal error\n",
  485. N_STR(host));
  486. if(notify_email && *notify_email != '\0')
  487. @@ -4711,7 +4872,7 @@ int main(int argc, char **argv)
  488. #endif
  489. #else
  490. - fprintf(stderr, "sorry, this mode is only available on platforms that the ");
  491. + fprintf(stderr, "sorry, this mode is only available on platforms where the ");
  492. fprintf(stderr, "IP address \ncan be determined. feel free to hack the code");
  493. fprintf(stderr, " though.\n");
  494. exit(1);
  495. @@ -4799,7 +4960,7 @@ int main(int argc, char **argv)
  496. }
  497. else
  498. {
  499. - show_message("could not resolve ip address for %s.\n", interface);
  500. + show_message("could not resolve ip address for %s\n", interface);
  501. exit(1);
  502. }
  503. close(sock);