3 cjb.net support by <tg@freewrt.org>
5 --- ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c Mon Mar 11 23:31:25 2002
6 +++ ez-ipupdate-3.0.11b8/ez-ipupdate.c Tue Jul 31 14:05:00 2007
8 #define JUSTL_REQUEST "/bin/controlpanel/dyndns/jlc.pl"
9 #define JUSTL_VERSION "2.0"
11 +#define CJB_DEFAULT_SERVER "www.cjb.net"
12 +#define CJB_DEFAULT_PORT "80"
13 +#define CJB_REQUEST "/cgi-bin/dynip.cgi"
15 #define DYNS_DEFAULT_SERVER "www.dyns.cx"
16 #define DYNS_DEFAULT_PORT "80"
17 #define DYNS_REQUEST "/postscript.php"
26 # include <sys/time.h>
32 -#if __linux__ || __SVR4 || __OpenBSD__ || __FreeBSD__ || __NetBSD__
33 +#if __GLIBC__ || __SVR4 || __OpenBSD__ || __FreeBSD__ || __NetBSD__
35 # include <sys/ioctl.h>
37 @@ -325,6 +332,10 @@ int JUSTL_update_entry(void);
38 int JUSTL_check_info(void);
39 static char *JUSTL_fields_used[] = { "server", "user", "host", NULL };
41 +int CJB_update_entry(void);
42 +int CJB_check_info(void);
43 +static char *CJB_fields_used[] = { "server", "user", NULL };
45 int DYNS_update_entry(void);
46 int DYNS_check_info(void);
47 static char *DYNS_fields_used[] = { "server", "user", "host", NULL };
48 @@ -474,6 +485,16 @@ struct service_t services[] = {
65 @@ -640,7 +661,7 @@ void print_usage( void )
66 fprintf(stdout, " -q, --quiet \t\t\tbe quiet\n");
67 fprintf(stdout, " -r, --retrys <num>\t\tnumber of trys (default: 1)\n");
68 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");
69 - 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");
70 + 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");
71 fprintf(stdout, " -s, --server <server[:port]>\tthe server to connect to\n");
72 fprintf(stdout, " -S, --service-type <server>\tthe type of service that you are using\n");
73 width = fprintf(stdout, "\t\t\t\ttry one of: ") + 4*7;
74 @@ -682,7 +703,7 @@ void print_credits( void )
76 void print_signalhelp( void )
78 - fprintf(stdout, "\nsignals are only really used when in daemon mode.\n\n");
79 + fprintf(stdout, "\nsignals are only really used when in daemon mode\n\n");
80 fprintf(stdout, "signals: \n");
81 fprintf(stdout, " HUP\t\tcauses it to re-read its config file\n");
82 fprintf(stdout, " TERM\t\twake up and possibly perform an update\n");
83 @@ -693,7 +714,7 @@ void print_signalhelp( void )
85 RETSIGTYPE sigint_handler(int sig)
87 - char message[] = "interupted.\n";
88 + char message[] = "interrupted\n";
90 write(2, message, sizeof(message)-1);
92 @@ -704,6 +725,10 @@ RETSIGTYPE sigint_handler(int sig)
102 RETSIGTYPE generic_sig_handler(int sig)
103 @@ -798,7 +823,7 @@ void show_message(char *fmt, ...)
104 sprintf(buf, "message incomplete because your OS sucks: %s\n", fmt);
107 - syslog(LOG_NOTICE, buf);
108 + syslog(LOG_NOTICE, "%s", buf);
112 @@ -1439,7 +1464,7 @@ int do_connect(int *sock, char *host, ch
113 if(!(options & OPT_QUIET))
116 - "connected to %s (%s) on port %d.\n",
117 + "connected to %s (%s) on port %d\n",
119 inet_ntoa(address.sin_addr),
120 ntohs(address.sin_port));
121 @@ -1683,7 +1708,7 @@ static int ODS_read_response(char *buf,
122 close(client_sockfd);
125 - if(strstr(buf, "\r\n") > 0)
126 + if(strstr(buf, "\n") != NULL)
130 @@ -1702,8 +1727,8 @@ int NULL_check_info(void)
132 if(options & OPT_DAEMON)
134 - fprintf(stderr, "no compile time default service was set therefor you must "
135 - "specify a service type.\n");
136 + fprintf(stderr, "no compile time default service was set, you must "
137 + "specify a service type\n");
141 @@ -2039,7 +2064,7 @@ int DYNDNS_update_entry(void)
143 else if(strstr(buf, "\nnumhost") != NULL)
145 - show_message("Too many or too few hosts found\n");
146 + show_message("too many or too few hosts found\n");
147 retval = UPDATERES_SHUTDOWN;
149 else if(strstr(buf, "\ndnserr") != NULL)
150 @@ -2051,17 +2076,17 @@ int DYNDNS_update_entry(void)
152 else if(strstr(buf, "\n911") != NULL)
154 - show_message("Ahhhh! call 911!\n");
155 + show_message("ahhhh! call 911!\n");
156 retval = UPDATERES_SHUTDOWN;
158 else if(strstr(buf, "\n999") != NULL)
160 - show_message("Ahhhh! call 999!\n");
161 + show_message("ahhhh! call 999!\n");
162 retval = UPDATERES_SHUTDOWN;
164 else if(strstr(buf, "\n!donator") != NULL)
166 - show_message("a feature requested is only available to donators, please donate.\n", host);
167 + show_message("a feature requested is only available to donators, please donate\n", host);
168 retval = UPDATERES_OK;
170 // this one should be last as it is a stupid string to signify waits
171 @@ -2095,9 +2120,9 @@ int DYNDNS_update_entry(void)
172 sprintf(reason, "problem parsing reason for wait response");
175 - show_message("Wait response received, waiting for %s before next update.\n",
176 + show_message("wait response received, waiting for %s before next update\n",
177 format_time(howlong));
178 - show_message("Wait response reason: %d\n", N_STR(reason));
179 + show_message("wait response reason: %d\n", N_STR(reason));
181 retval = UPDATERES_ERROR;
183 @@ -3370,7 +3395,7 @@ int GNUDIP_check_info(void)
185 if(!(options & OPT_QUIET))
187 - fprintf(stderr, "warning: for GNUDIP the \"address\" parpameter is only used if set to \"0.0.0.0\" thus making an offline request.\n");
188 + fprintf(stderr, "warning: for GNUDIP the \"address\" parameter is only used if set to \"0.0.0.0\" thus making an offline request\n");
192 @@ -3392,7 +3417,7 @@ int GNUDIP_update_entry(void)
194 // send an offline request if address 0.0.0.0 is used
195 // otherwise, we ignore the address and send an update request
196 - gnudip_request[0] = strcmp(address, "0.0.0.0") == 0 ? '1' : '0';
197 + gnudip_request[0] = address && strcmp(address, "0.0.0.0") == 0 ? '1' : '0';
198 gnudip_request[1] = '\0';
201 @@ -3660,6 +3685,140 @@ int JUSTL_update_entry(void)
202 return(UPDATERES_OK);
205 +int CJB_check_info(void)
207 + char buf[BUFSIZ+1];
209 + if(interface == NULL && address == NULL)
211 + if(options & OPT_DAEMON)
213 + fprintf(stderr, "you must provide either an interface or an address\n");
216 + if(interface) { free(interface); }
217 + printf("interface: ");
219 + fgets(buf, BUFSIZ, stdin);
221 + option_handler(CMD_interface, buf);
224 + warn_fields(service->fields_used);
229 +int CJB_update_entry(void)
231 + char buf[BUFFER_SIZE+1];
237 + buf[BUFFER_SIZE] = '\0';
239 + if(do_connect((int*)&client_sockfd, server, port) != 0)
241 + if(!(options & OPT_QUIET))
243 + show_message("error connecting to %s:%s\n", server, port);
245 + return(UPDATERES_ERROR);
248 + snprintf(buf, BUFFER_SIZE, "GET %s?", request);
250 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "username", user_name);
252 + snprintf(buf, BUFFER_SIZE, "%s=%s", "password", password);
255 + /* cjb does IP address autodetection */
256 + snprintf(buf, BUFFER_SIZE, "&%s=%s", "ip", address);
259 + snprintf(buf, BUFFER_SIZE, " HTTP/1.0\015\012");
261 + snprintf(buf, BUFFER_SIZE, "User-Agent: %s-%s %s [%s] (%s)\015\012",
262 + "ez-update", VERSION, OS, (options & OPT_DAEMON) ? "daemon" : "", "by OpenADK");
264 + snprintf(buf, BUFFER_SIZE, "\015\012");
270 + while((bytes=read_input(bp, BUFFER_SIZE-btot)) > 0)
274 + dprintf((stderr, "btot: %d\n", btot));
276 + close(client_sockfd);
279 + dprintf((stderr, "server output: %s\n", buf));
281 + if(sscanf(buf, " HTTP/1.%*c %3d", &ret) != 1)
289 + if(!(options & OPT_QUIET))
291 + show_message("strange server response, are you connecting to the right server?\n");
293 + return(UPDATERES_ERROR);
297 + if(strstr(buf, " updated ") != NULL)
299 + if(!(options & OPT_QUIET))
301 + printf("request successful\n");
306 + show_message("error processing request\n");
307 + if(!(options & OPT_QUIET))
309 + fprintf(stderr, "server output: %s\n", buf);
311 + return(UPDATERES_ERROR);
316 + if(!(options & OPT_QUIET))
318 + show_message("authentication failure\n");
320 + return(UPDATERES_SHUTDOWN);
324 + if(!(options & OPT_QUIET))
326 + // reuse the auth buffer
328 + sscanf(buf, " HTTP/1.%*c %*3d %255[^\r\n]", auth);
329 + show_message("unknown return code: %d\n", ret);
330 + show_message("server response: %s\n", auth);
332 + return(UPDATERES_ERROR);
336 + return(UPDATERES_OK);
339 int DYNS_check_info(void)
342 @@ -3943,22 +4102,22 @@ int HN_update_entry(void)
346 - show_message("Last update was less than %d seconds ago.\n", 300);
347 + show_message("last update was less than %d seconds ago\n", 300);
348 return(UPDATERES_ERROR);
352 - show_message("Server error.\n");
353 + show_message("server error\n");
354 return(UPDATERES_ERROR);
358 - show_message("Failure because account is frozen (by admin).\n");
359 + show_message("failure because account is frozen (by admin)\n");
360 return(UPDATERES_SHUTDOWN);
364 - show_message("Failure because account is locked (by user).\n");
365 + show_message("failure because account is locked (by user)\n");
366 return(UPDATERES_SHUTDOWN);
369 @@ -4215,8 +4374,6 @@ int HEIPV6TB_update_entry(void)
376 if(!(options & OPT_QUIET))
378 @@ -4349,7 +4506,7 @@ void handle_sig(int sig)
382 - show_message("SIGHUP recieved, re-reading config file\n");
383 + show_message("SIGHUP received, re-reading config file\n");
384 if(parse_conf_file(config_file, conf_commands) != 0)
386 show_message("error parsing config file \"%s\"\n", config_file);
387 @@ -4384,6 +4541,7 @@ void handle_sig(int sig)
389 int main(int argc, char **argv)
392 int ifresolve_warned = 0;
395 @@ -4395,9 +4553,10 @@ int main(int argc, char **argv)
399 - dprintf((stderr, "staring...\n"));
400 + dprintf((stderr, "starting...\n"));
402 - program_name = argv[0];
403 + tmp = strrchr(argv[0], '/');
404 + program_name = tmp ? tmp + 1 : argv[0];
407 timeout.tv_sec = DEFAULT_TIMEOUT;
408 @@ -4417,7 +4576,7 @@ int main(int argc, char **argv)
410 if(!(options & OPT_QUIET) && !(options & OPT_DAEMON))
412 - fprintf(stderr, "ez-ipupdate Version %s\nCopyright (C) 1998-2001 Angus Mackay.\n", VERSION);
413 + fprintf(stderr, "%s Version %s\nCopyright (C) 1998-2001 Angus Mackay\n", program_name, VERSION);
416 dprintf((stderr, "options: 0x%04X\n", options));
417 @@ -4434,7 +4593,7 @@ int main(int argc, char **argv)
419 if(service->check_info() != 0)
421 - fprintf(stderr, "invalid data to perform requested action.\n");
422 + fprintf(stderr, "invalid data to perform requested action\n");
426 @@ -4456,13 +4615,13 @@ int main(int argc, char **argv)
427 dprintf((stderr, "user_name: %s\n", user_name));
428 dprintf((stderr, "password: %s\n", password));
430 - if(*user_name == '\0')
431 + if(*user_name == '\0' && !(options & OPT_DAEMON))
433 printf("user name: ");
434 fgets(user_name, sizeof(user_name), stdin);
437 - if(*password == '\0')
438 + if(*password == '\0' && !(options & OPT_DAEMON))
440 strncpy(password, getpass("password: "), sizeof(password));
442 @@ -4480,7 +4639,7 @@ int main(int argc, char **argv)
444 if(service->check_info() != 0)
446 - fprintf(stderr, "invalid data to perform requested action.\n");
447 + fprintf(stderr, "invalid data to perform requested action\n");
451 @@ -4503,7 +4662,7 @@ int main(int argc, char **argv)
453 if(interface == NULL)
455 - fprintf(stderr, "invalid data to perform requested action.\n");
456 + fprintf(stderr, "invalid data to perform requested action\n");
457 fprintf(stderr, "you must provide an interface for daemon mode");
460 @@ -4519,23 +4678,25 @@ int main(int argc, char **argv)
461 if(fork() > 0) { exit(0); } /* parent */
465 + openlog(program_name, LOG_PID, LOG_DAEMON );
466 + //options |= OPT_QUIET;
468 + show_message("version %s, interface %s, host %s, server %s, service %s\n",
469 + VERSION, N_STR(interface), N_STR(host), server, service->title);
472 if(pid_file && pid_file_create(pid_file) != 0)
474 - fprintf(stderr, "exiting...\n");
475 + show_message("could not create pid file %s (%s), exiting\n",
476 + pid_file, strerror(errno));
485 - openlog(program_name, LOG_PID, LOG_USER );
486 - options |= OPT_QUIET;
488 - show_message("ez-ipupdate Version %s, Copyright (C) 1998-2001 Angus Mackay.\n",
490 - show_message("%s started for interface %s host %s using server %s and service %s\n",
491 - program_name, N_STR(interface), N_STR(host), server, service->title);
493 memset(&sin, 0, sizeof(sin));
496 @@ -4560,7 +4721,7 @@ int main(int argc, char **argv)
497 strftime(timebuf, sizeof(timebuf), "%Y/%m/%d %H:%M", ts);
498 show_message("got last update %s on %s from cache file\n", ipstr, timebuf);
501 + else if(ipstr||ipdate)
503 show_message("malformed cache file: %s\n", cache_file);
505 @@ -4647,7 +4808,7 @@ int main(int argc, char **argv)
509 - show_message("failure to update %s->%s (%s)\n",
510 + show_message("failed to update %s->%s (%s)\n",
511 interface, inet_ntoa(sin.sin_addr), N_STR(host));
512 memset(&sin, 0, sizeof(sin));
514 @@ -4671,7 +4832,7 @@ int main(int argc, char **argv)
515 dprintf((stderr, "updateres: %d\n", updateres));
516 if(updateres == UPDATERES_SHUTDOWN)
518 - show_message("shuting down updater for %s due to fatal error\n",
519 + show_message("shutting down updater for %s due to fatal error\n",
522 if(notify_email && *notify_email != '\0')
523 @@ -4711,7 +4872,7 @@ int main(int argc, char **argv)
527 - fprintf(stderr, "sorry, this mode is only available on platforms that the ");
528 + fprintf(stderr, "sorry, this mode is only available on platforms where the ");
529 fprintf(stderr, "IP address \ncan be determined. feel free to hack the code");
530 fprintf(stderr, " though.\n");
532 @@ -4799,7 +4960,7 @@ int main(int argc, char **argv)
536 - show_message("could not resolve ip address for %s.\n", interface);
537 + show_message("could not resolve ip address for %s\n", interface);