-
Notifications
You must be signed in to change notification settings - Fork 1
/
ez-ipupdate.c
4900 lines (4342 loc) · 118 KB
/
ez-ipupdate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ============================================================================
* Copyright (C) 1998-2001 Angus Mackay. All rights reserved;
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*/
/*
* ez-ipupdate
*
* a very simple dynDNS client for the ez-ip dynamic dns service
* (http://www.ez-ip.net).
*
* why this program when something like:
* curl -u user:pass http://www.ez-ip.net/members/update/?key=val&...
* would do the trick? because there are nicer clients for other OSes and
* I don't like to see UNIX get the short end of the stick.
*
* tested under Linux and Solaris.
*
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
// you man very well need to edit this, don't worry though, email is only sent
// if bad things happend and it has to exit when in daemon mode.
#define SEND_EMAIL_CMD "mail"
#define EZIP_DEFAULT_SERVER "www.EZ-IP.Net"
#define EZIP_DEFAULT_PORT "80"
#define EZIP_REQUEST "/members/update/"
#define PGPOW_DEFAULT_SERVER "www.penguinpowered.com"
#define PGPOW_DEFAULT_PORT "2345"
#define PGPOW_REQUEST "update"
#define PGPOW_VERSION "1.0"
#define DHS_DEFAULT_SERVER "members.dhs.org"
#define DHS_DEFAULT_PORT "80"
#define DHS_REQUEST "/nic/hosts"
#define DHS_SUCKY_TIMEOUT 60
#define DYNDNS_DEFAULT_SERVER "members.dyndns.org"
#define DYNDNS_DEFAULT_PORT "80"
#define DYNDNS_REQUEST "/nic/update"
#define DYNDNS_STAT_REQUEST "/nic/update"
#define DYNDNS_MAX_INTERVAL (25*24*3600)
#define ODS_DEFAULT_SERVER "update.ods.org"
#define ODS_DEFAULT_PORT "7070"
#define ODS_REQUEST "update"
#define TZO_DEFAULT_SERVER "cgi.tzo.com"
#define TZO_DEFAULT_PORT "80"
#define TZO_REQUEST "/webclient/signedon.html"
#define GNUDIP_DEFAULT_SERVER ""
#define GNUDIP_DEFAULT_PORT "3495"
#define GNUDIP_REQUEST "0"
#define EASYDNS_DEFAULT_SERVER "members.easydns.com"
#define EASYDNS_DEFAULT_PORT "80"
#define EASYDNS_REQUEST "/dyn/ez-ipupdate.php"
#define EASYDNS_PARTNER_DEFAULT_SERVER "api.easydns.com"
#define EASYDNS_PARTNER_DEFAULT_PORT "80"
#define EASYDNS_PARTNER_REQUEST "/dyn/ez-ipupdate.php"
#define JUSTL_DEFAULT_SERVER "www.justlinux.com"
#define JUSTL_DEFAULT_PORT "80"
#define JUSTL_REQUEST "/bin/controlpanel/dyndns/jlc.pl"
#define JUSTL_VERSION "2.0"
#define DYNS_DEFAULT_SERVER "www.dyns.cx"
#define DYNS_DEFAULT_PORT "80"
#define DYNS_REQUEST "/postscript.php"
#define HN_DEFAULT_SERVER "dup.hn.org"
#define HN_DEFAULT_PORT "80"
#define HN_REQUEST "/vanity/update"
#define ZONEEDIT_DEFAULT_SERVER "www.zoneedit.com"
#define ZONEEDIT_DEFAULT_PORT "80"
#define ZONEEDIT_REQUEST "/auth/dynamic.html"
#define HEIPV6TB_DEFAULT_SERVER "ipv6tb.he.net"
#define HEIPV6TB_DEFAULT_PORT "80"
#define HEIPV6TB_REQUEST "/index.cgi"
#define DEFAULT_TIMEOUT 120
#define DEFAULT_UPDATE_PERIOD 120
#define DEFAULT_RESOLV_PERIOD 30
#ifdef DEBUG
# define BUFFER_SIZE (16*1024)
#else
# define BUFFER_SIZE (4*1024-1)
#endif
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#if HAVE_FCNTL_H
# include <fcntl.h>
#endif
#include <netinet/in.h>
#if HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#if HAVE_ERRNO_H
# include <errno.h>
#endif
#include <netdb.h>
#include <sys/socket.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_SIGNAL_H
# include <signal.h>
#endif
#if HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#if HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#if HAVE_SYSLOG_H
# include <syslog.h>
#endif
#if HAVE_STDARG_H
# include <stdarg.h>
#endif
#include <error.h>
#if HAVE_PWD_H && HAVE_GRP_H
# include <pwd.h>
# include <grp.h>
#endif
#if defined(HAVE_FORK) && !defined(HAVE_VFORK)
# define vfork fork
#endif
#if USE_MD5
# include <md5.h>
# define MD5_DIGEST_BYTES (16)
#endif
#if __linux__ || __SVR4 || __OpenBSD__ || __FreeBSD__ || __NetBSD__
# define IF_LOOKUP 1
# include <sys/ioctl.h>
# include <net/if.h>
# ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
# endif
#endif
#include <dprintf.h>
#include <conf_file.h>
#include <cache_file.h>
#include <pid_file.h>
#if !defined(__GNUC__) && !defined(HAVE_SNPRINTF)
#error "get gcc, fix this code, or find yourself a snprintf!"
#else
# if HAVE_SNPRINTF
# define snprintf(x, y, z...) snprintf(x, y, ## z)
# else
# define snprintf(x, y, z...) sprintf(x, ## z)
# endif
#endif
#if HAVE_VSNPRINTF
# define vsnprintf(x, y, z...) vsnprintf(x, y, ## z)
#else
# define vsnprintf(x, y, z...) vsprintf(x, ## z)
#endif
#ifndef HAVE_HERROR
# define herror(x) fprintf(stderr, "%s: error\n", x)
#endif
#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0]))
#define N_STR(x) (x == NULL ? "(null)" : x)
#ifndef OS
# define OS "unknown"
#endif
// the min period for checking the interface
#define MIN_UPDATE_PERIOD 10
// the min/max time to wait if we fail to update
#define MIN_WAIT_PERIOD 300
#define MAX_WAIT_PERIOD (2*3600)
// the min time that max-period can be set to
#define MIN_MAXINTERVAL (24*3600)
// the max time we will wait if the server tells us to
#define MAX_WAITRESPONSE_WAIT (24*3600)
#define MAX_MESSAGE_LEN 256
#define ARGLENGTH 32
/**************************************************/
struct service_t
{
char *title;
char *names[3];
void (*init)(void);
int (*update_entry)(void);
int (*check_info)(void);
char **fields_used;
char *default_server;
char *default_port;
char *default_request;
};
enum {
UPDATERES_OK = 0,
UPDATERES_ERROR,
UPDATERES_SHUTDOWN,
};
/**************************************************/
char *program_name = NULL;
char *cache_file = NULL;
char *config_file = NULL;
char *server = NULL;
char *port = NULL;
char user[256];
char auth[512];
char user_name[128];
char password[128];
char *address = NULL;
char *request = NULL;
char *request_over_ride = NULL;
int wildcard = 0;
char *mx = NULL;
char *url = NULL;
char *host = NULL;
char *cloak_title = NULL;
char *interface = NULL;
int ntrys = 1;
int update_period = DEFAULT_UPDATE_PERIOD;
int resolv_period = DEFAULT_RESOLV_PERIOD;
struct timeval timeout;
int max_interval = 0;
int service_set = 0;
char *post_update_cmd = NULL;
char *post_update_cmd_arg = NULL;
int connection_type = 1;
time_t last_update = 0;
char *notify_email = NULL;
char *pid_file = NULL;
char *partner = NULL;
static volatile int client_sockfd;
static volatile int last_sig = 0;
/* service objects for various services */
// this one is for when people don't configure a default service at build time
int NULL_check_info(void);
static char *NULL_fields_used[] = { NULL };
int EZIP_update_entry(void);
int EZIP_check_info(void);
static char *EZIP_fields_used[] = { "server", "user", "address", "wildcard", "mx", "url", "host", NULL };
int PGPOW_update_entry(void);
int PGPOW_check_info(void);
static char *PGPOW_fields_used[] = { "server", "host", NULL };
int DHS_update_entry(void);
int DHS_check_info(void);
static char *DHS_fields_used[] = { "server", "user", "address", "wildcard", "mx", "url", "host", NULL };
void DYNDNS_init(void);
int DYNDNS_update_entry(void);
int DYNDNS_check_info(void);
static char *DYNDNS_fields_used[] = { "server", "user", "address", "wildcard", "mx", "host", NULL };
static char *DYNDNS_STAT_fields_used[] = { "server", "user", "address", "wildcard", "mx", "host", NULL };
int ODS_update_entry(void);
int ODS_check_info(void);
static char *ODS_fields_used[] = { "server", "host", "address", NULL };
int TZO_update_entry(void);
int TZO_check_info(void);
static char *TZO_fields_used[] = { "server", "user", "address", "host", "connection-type", NULL };
int EASYDNS_update_entry(void);
int EASYDNS_check_info(void);
static char *EASYDNS_fields_used[] = { "server", "user", "address", "wildcard", "mx", "host", NULL };
int EASYDNS_PARTNER_update_entry(void);
int EASYDNS_PARTNER_check_info(void);
static char *EASYDNS_PARTNER_fields_used[] = { "server", "partner", "user", "address", "wildcard", "host", NULL };
#ifdef USE_MD5
int GNUDIP_update_entry(void);
int GNUDIP_check_info(void);
static char *GNUDIP_fields_used[] = { "server", "user", "host", "address", NULL };
#endif
int JUSTL_update_entry(void);
int JUSTL_check_info(void);
static char *JUSTL_fields_used[] = { "server", "user", "host", NULL };
int DYNS_update_entry(void);
int DYNS_check_info(void);
static char *DYNS_fields_used[] = { "server", "user", "host", NULL };
int HN_update_entry(void);
int HN_check_info(void);
static char *HN_fields_used[] = { "server", "user", "address", NULL };
int ZONEEDIT_update_entry(void);
int ZONEEDIT_check_info(void);
static char *ZONEEDIT_fields_used[] = { "server", "user", "address", "mx", "host", NULL };
int HEIPV6TB_update_entry(void);
int HEIPV6TB_check_info(void);
static char *HEIPV6TB_fields_used[] = { "server", "user", NULL };
struct service_t services[] = {
{ "NULL",
{ "null", "NULL", 0, },
NULL,
NULL,
NULL_check_info,
NULL_fields_used,
"",
"",
""
},
{ "ez-ip",
{ "ezip", "ez-ip", 0, },
NULL,
EZIP_update_entry,
EZIP_check_info,
EZIP_fields_used,
EZIP_DEFAULT_SERVER,
EZIP_DEFAULT_PORT,
EZIP_REQUEST
},
{ "justlinux v1.0 (penguinpowered)",
{ "pgpow", "penguinpowered", 0, },
NULL,
PGPOW_update_entry,
PGPOW_check_info,
PGPOW_fields_used,
PGPOW_DEFAULT_SERVER,
PGPOW_DEFAULT_PORT,
PGPOW_REQUEST
},
{ "dhs",
{ "dhs", 0, 0, },
NULL,
DHS_update_entry,
DHS_check_info,
DHS_fields_used,
DHS_DEFAULT_SERVER,
DHS_DEFAULT_PORT,
DHS_REQUEST
},
{ "dyndns",
{ "dyndns", 0, 0, },
DYNDNS_init,
DYNDNS_update_entry,
DYNDNS_check_info,
DYNDNS_fields_used,
DYNDNS_DEFAULT_SERVER,
DYNDNS_DEFAULT_PORT,
DYNDNS_REQUEST
},
{ "dyndns-static",
{ "dyndns-static", "dyndns-stat", "statdns", },
DYNDNS_init,
DYNDNS_update_entry,
DYNDNS_check_info,
DYNDNS_STAT_fields_used,
DYNDNS_DEFAULT_SERVER,
DYNDNS_DEFAULT_PORT,
DYNDNS_STAT_REQUEST
},
{ "dyndns-custom",
{ "dyndns-custom", "mydyndns", 0 },
DYNDNS_init,
DYNDNS_update_entry,
DYNDNS_check_info,
DYNDNS_STAT_fields_used,
DYNDNS_DEFAULT_SERVER,
DYNDNS_DEFAULT_PORT,
DYNDNS_REQUEST
},
{ "ods",
{ "ods", 0, 0, },
NULL,
ODS_update_entry,
ODS_check_info,
ODS_fields_used,
ODS_DEFAULT_SERVER,
ODS_DEFAULT_PORT,
ODS_REQUEST
},
{ "tzo",
{ "tzo", 0, 0, },
NULL,
TZO_update_entry,
TZO_check_info,
TZO_fields_used,
TZO_DEFAULT_SERVER,
TZO_DEFAULT_PORT,
TZO_REQUEST
},
{ "easydns",
{ "easydns", 0, 0, },
NULL,
EASYDNS_update_entry,
EASYDNS_check_info,
EASYDNS_fields_used,
EASYDNS_DEFAULT_SERVER,
EASYDNS_DEFAULT_PORT,
EASYDNS_REQUEST
},
{ "easydns-partner",
{ "easydns-partner", 0, 0, },
NULL,
EASYDNS_PARTNER_update_entry,
EASYDNS_PARTNER_check_info,
EASYDNS_PARTNER_fields_used,
EASYDNS_PARTNER_DEFAULT_SERVER,
EASYDNS_PARTNER_DEFAULT_PORT,
EASYDNS_PARTNER_REQUEST
},
#ifdef USE_MD5
{ "gnudip",
{ "gnudip", 0, 0, },
NULL,
GNUDIP_update_entry,
GNUDIP_check_info,
GNUDIP_fields_used,
GNUDIP_DEFAULT_SERVER,
GNUDIP_DEFAULT_PORT,
GNUDIP_REQUEST
},
#endif
{ "justlinux v2.0 (penguinpowered)",
{ "justlinux", 0, 0, },
NULL,
JUSTL_update_entry,
JUSTL_check_info,
JUSTL_fields_used,
JUSTL_DEFAULT_SERVER,
JUSTL_DEFAULT_PORT,
JUSTL_REQUEST
},
{ "dyns",
{ "dyns", 0, 0, },
NULL,
DYNS_update_entry,
DYNS_check_info,
DYNS_fields_used,
DYNS_DEFAULT_SERVER,
DYNS_DEFAULT_PORT,
DYNS_REQUEST
},
{ "hammer node",
{ "hn", 0, 0, },
NULL,
HN_update_entry,
HN_check_info,
HN_fields_used,
HN_DEFAULT_SERVER,
HN_DEFAULT_PORT,
HN_REQUEST
},
{ "zoneedit",
{ "zoneedit", 0, 0, },
NULL,
ZONEEDIT_update_entry,
ZONEEDIT_check_info,
ZONEEDIT_fields_used,
ZONEEDIT_DEFAULT_SERVER,
ZONEEDIT_DEFAULT_PORT,
ZONEEDIT_REQUEST
},
{ "heipv6tb",
{ "heipv6tb", 0, 0, },
NULL,
HEIPV6TB_update_entry,
HEIPV6TB_check_info,
HEIPV6TB_fields_used,
HEIPV6TB_DEFAULT_SERVER,
HEIPV6TB_DEFAULT_PORT,
HEIPV6TB_REQUEST
},
};
static struct service_t *service = NULL;
int options;
#define OPT_DEBUG 0x0001
#define OPT_DAEMON 0x0004
#define OPT_QUIET 0x0008
#define OPT_FOREGROUND 0x0010
#define OPT_OFFLINE 0x0020
enum {
CMD__start = 1,
CMD_service_type,
CMD_server,
CMD_request,
CMD_user,
CMD_address,
CMD_wildcard,
CMD_mx,
CMD_max_interval,
CMD_url,
CMD_host,
CMD_cloak_title,
CMD_interface,
CMD_retrys,
CMD_resolv_period,
CMD_period,
CMD_daemon,
CMD_debug,
CMD_execute,
CMD_foreground,
CMD_quiet,
CMD_timeout,
CMD_run_as_user,
CMD_run_as_euser,
CMD_connection_type,
CMD_cache_file,
CMD_notify_email,
CMD_pid_file,
CMD_offline,
CMD_partner,
CMD__end
};
int conf_handler(struct conf_cmd *cmd, char *arg);
static struct conf_cmd conf_commands[] = {
{ CMD_address, "address", CONF_NEED_ARG, 1, conf_handler, "%s=<ip address>" },
{ CMD_cache_file, "cache-file", CONF_NEED_ARG, 1, conf_handler, "%s=<cache file>" },
{ CMD_cloak_title, "cloak-title", CONF_NEED_ARG, 1, conf_handler, "%s=<title>" },
{ CMD_daemon, "daemon", CONF_NO_ARG, 1, conf_handler, "%s=<command>" },
{ CMD_execute, "execute", CONF_NEED_ARG, 1, conf_handler, "%s=<shell command>" },
{ CMD_debug, "debug", CONF_NO_ARG, 1, conf_handler, "%s" },
{ CMD_foreground, "foreground", CONF_NO_ARG, 1, conf_handler, "%s" },
{ CMD_pid_file, "pid-file", CONF_NEED_ARG, 1, conf_handler, "%s=<file>" },
{ CMD_host, "host", CONF_NEED_ARG, 1, conf_handler, "%s=<host>" },
{ CMD_interface, "interface", CONF_NEED_ARG, 1, conf_handler, "%s=<interface>" },
{ CMD_mx, "mx", CONF_NEED_ARG, 1, conf_handler, "%s=<mail exchanger>" },
{ CMD_max_interval, "max-interval", CONF_NEED_ARG, 1, conf_handler, "%s=<number of seconds between updates>" },
{ CMD_notify_email, "notify-email", CONF_NEED_ARG, 1, conf_handler, "%s=<address to email if bad things happen>" },
{ CMD_offline, "offline", CONF_NO_ARG, 1, conf_handler, "%s" },
{ CMD_retrys, "retrys", CONF_NEED_ARG, 1, conf_handler, "%s=<number of trys>" },
{ CMD_server, "server", CONF_NEED_ARG, 1, conf_handler, "%s=<server name>" },
{ CMD_service_type, "service-type", CONF_NEED_ARG, 1, conf_handler, "%s=<service type>" },
{ CMD_timeout, "timeout", CONF_NEED_ARG, 1, conf_handler, "%s=<sec.millisec>" },
{ CMD_resolv_period, "resolv-period", CONF_NEED_ARG, 1, conf_handler, "%s=<time between failed resolve attempts>" },
{ CMD_period, "period", CONF_NEED_ARG, 1, conf_handler, "%s=<time between update attempts>" },
{ CMD_url, "url", CONF_NEED_ARG, 1, conf_handler, "%s=<url>" },
{ CMD_user, "user", CONF_NEED_ARG, 1, conf_handler, "%s=<user name>[:password]" },
{ CMD_run_as_user, "run-as-user", CONF_NEED_ARG, 1, conf_handler, "%s=<user>" },
{ CMD_run_as_euser, "run-as-euser", CONF_NEED_ARG, 1, conf_handler, "%s=<user> (this is not secure)" },
{ CMD_wildcard, "wildcard", CONF_NO_ARG, 1, conf_handler, "%s" },
{ CMD_quiet, "quiet", CONF_NO_ARG, 1, conf_handler, "%s" },
{ CMD_connection_type, "connection-type", CONF_NEED_ARG, 1, conf_handler, "%s=<connection type>" },
{ CMD_request, "request", CONF_NEED_ARG, 1, conf_handler, "%s=<request uri>" },
{ CMD_partner, "partner", CONF_NEED_ARG, 1, conf_handler, "%s=<easydns partner>" },
{ 0, 0, 0, 0, 0 }
};
/**************************************************/
void print_usage( void );
void print_version( void );
void parse_args( int argc, char **argv );
int do_connect(int *sock, char *host, char *port);
void base64Encode(char *intext, char *output);
int main( int argc, char **argv );
void warn_fields(char **okay_fields);
static int is_in_list(char *needle, char **haystack);
/**************************************************/
void print_usage( void )
{
int i;
int width;
fprintf(stdout, "usage: ");
fprintf(stdout, "%s [options] \n\n", program_name);
fprintf(stdout, " Options are:\n");
fprintf(stdout, " -a, --address <ip address>\tstring to send as your ip address\n");
fprintf(stdout, " -b, --cache-file <file>\tfile to use for caching the ipaddress\n");
fprintf(stdout, " -c, --config-file <file>\tconfiguration file, almost all arguments can be\n");
fprintf(stdout, "\t\t\t\tgiven with: <name>[=<value>]\n\t\t\t\tto see a list of possible config commands\n");
fprintf(stdout, "\t\t\t\ttry \"echo help | %s -c -\"\n", program_name);
fprintf(stdout, " -d, --daemon\t\t\trun as a daemon periodicly updating if \n\t\t\t\tnecessary\n");
#ifdef DEBUG
fprintf(stdout, " -D, --debug\t\t\tturn on debuggin\n");
#endif
fprintf(stdout, " -e, --execute <command>\tshell command to execute after a successful\n\t\t\t\tupdate\n");
fprintf(stdout, " -f, --foreground\t\twhen running as a daemon run in the foreground\n");
fprintf(stdout, " -F, --pidfile <file>\t\tuse <file> as a pid file\n");
fprintf(stdout, " -g, --request-uri <uri>\tURI to send updates to\n");
fprintf(stdout, " -h, --host <host>\t\tstring to send as host parameter\n");
fprintf(stdout, " -i, --interface <iface>\twhich interface to use\n");
fprintf(stdout, " -L, --cloak_title <host>\tsome stupid thing for DHS only\n");
fprintf(stdout, " -m, --mx <mail exchange>\tstring to send as your mail exchange\n");
fprintf(stdout, " -M, --max-interval <# of sec>\tmax time in between updates\n");
fprintf(stdout, " -N, --notify-email <email>\taddress to send mail to if bad things happen\n");
fprintf(stdout, " -o, --offline\t\t\tset to off line mode\n");
fprintf(stdout, " -p, --resolv-period <sec>\tperiod to check IP if it can't be resolved\n");
fprintf(stdout, " -P, --period <# of sec>\tperiod to check IP in daemon \n\t\t\t\tmode (default: 1800 seconds)\n");
fprintf(stdout, " -q, --quiet \t\t\tbe quiet\n");
fprintf(stdout, " -r, --retrys <num>\t\tnumber of trys (default: 1)\n");
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");
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");
fprintf(stdout, " -s, --server <server[:port]>\tthe server to connect to\n");
fprintf(stdout, " -S, --service-type <server>\tthe type of service that you are using\n");
width = fprintf(stdout, "\t\t\t\ttry one of: ") + 4*7;
for(i=0; i<ARRAY_LEN(services); i++)
{
if(width > 60) { width = fprintf(stdout, "\n\t\t\t\t") -1 + 4*7; }
width += fprintf(stdout, "%s ", services[i].names[0]);
}
fprintf(stdout, "\n");
fprintf(stdout, " -t, --timeout <sec.millisec>\tthe amount of time to wait on I/O\n");
fprintf(stdout, " -T, --connection-type <num>\tnumber sent to TZO as your connection \n\t\t\t\ttype (default: 1)\n");
fprintf(stdout, " -U, --url <url>\t\tstring to send as the url parameter\n");
fprintf(stdout, " -u, --user <user[:passwd]>\tuser ID and password, if either is left blank \n\t\t\t\tthey will be prompted for\n");
fprintf(stdout, " -w, --wildcard\t\tset your domain to have a wildcard alias\n");
fprintf(stdout, " -z, --partner <partner>\tspecify easyDNS partner (for easydns-partner \n\t\t\t\tservices)\n");
fprintf(stdout, " --help\t\t\tdisplay this help and exit\n");
fprintf(stdout, " --version\t\t\toutput version information and exit\n");
fprintf(stdout, " --credits\t\t\tprint the credits and exit\n");
fprintf(stdout, " --signalhelp\t\tprint help about signals\n");
fprintf(stdout, "\n");
}
void print_version( void )
{
fprintf(stdout, "%s: - %s - $Id: ez-ipupdate.c,v 1.48 2001/07/17 00:49:41 amackay Exp $\n", program_name, VERSION);
}
void print_credits( void )
{
fprintf( stdout, "AUTHORS / CONTRIBUTORS\n"
" Angus Mackay <[email protected]>\n"
" Jeremy Bopp <[email protected]>\n"
" Mark Jeftovic <[email protected]>\n"
" Stefaan Ponnet <[email protected]>\n"
" Colin Viebrock <[email protected]>\n"
" Tim Brown <[email protected]>\n"
"\n" );
}
void print_signalhelp( void )
{
fprintf(stdout, "\nsignals are only really used when in daemon mode.\n\n");
fprintf(stdout, "signals: \n");
fprintf(stdout, " HUP\t\tcauses it to re-read its config file\n");
fprintf(stdout, " TERM\t\twake up and possibly perform an update\n");
fprintf(stdout, " QUIT\t\tshutdown\n");
fprintf(stdout, "\n");
}
#if HAVE_SIGNAL_H
RETSIGTYPE sigint_handler(int sig)
{
char message[] = "interupted.\n";
close(client_sockfd);
write(2, message, sizeof(message)-1);
#if HAVE_GETPID
if(pid_file)
{
pid_file_delete(pid_file);
}
#endif
exit(1);
}
RETSIGTYPE generic_sig_handler(int sig)
{
last_sig = sig;
}
#endif
int get_duration(char *str)
{
char *multchar;
int mult;
char save;
int duration;
for(multchar=str; *multchar != '\0'; multchar++);
if(multchar != str) { multchar--; }
if(*multchar == '\0' || isdigit(*multchar)) { mult = 1; multchar++; }
else if(*multchar == 'M') { mult = 60; }
else if(*multchar == 'H') { mult = 60*60; }
else if(*multchar == 'd') { mult = 60*60*24; }
else if(*multchar == 'w') { mult = 60*60*24*7; }
else if(*multchar == 'f') { mult = 60*60*24*7*2; }
else if(*multchar == 'm') { mult = 60*60*24*30; }
else if(*multchar == 'y') { mult = 60*60*24*365; }
else
{
fprintf(stderr, "invalid multiplier: %c\n", *multchar);
fprintf(stderr, "valid multipliers:\n");
fprintf(stderr, " %c -> %s (%d)\n", 'M', "Minute", 60);
fprintf(stderr, " %c -> %s (%d)\n", 'H', "Hour", 60*60);
fprintf(stderr, " %c -> %s (%d)\n", 'd', "day", 60*60*24);
fprintf(stderr, " %c -> %s (%d)\n", 'w', "week", 60*60*24*7);
fprintf(stderr, " %c -> %s (%d)\n", 'f', "fortnight", 60*60*24*7*2);
fprintf(stderr, " %c -> %s (%d)\n", 'm', "month", 60*60*24*30);
fprintf(stderr, " %c -> %s (%d)\n", 'y', "year", 60*60*24*365);
exit(1);
}
save = *multchar;
*multchar = '\0';
duration = strtol(str, NULL, 0) * mult;
*multchar = save;
return(duration);
}
const char* format_time(int seconds)
{
static char buf[16];
snprintf(buf, sizeof(buf), "%d:%02d:%02d", seconds/(3600),
(seconds%(3600))/(60), (seconds%60));
return(buf);
}
/*
* like "chomp" in perl, take off trailing newline chars
*/
char *chomp(char *buf)
{
char *p;
for(p=buf; *p != '\0'; p++);
if(p != buf) { p--; }
while(p>=buf && (*p == '\n' || *p == '\r'))
{
*p-- = '\0';
}
return(buf);
}
/*
* show_message
*
* if we are running in daemon mode then log to syslog, if not just output to
* stderr.
*
*/
void show_message(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if(options & OPT_DAEMON && !(options & OPT_FOREGROUND))
{
char buf[MAX_MESSAGE_LEN];
#if defined(HAVE_VSPRINTF) || defined(HAVE_VSNPRINTF)
vsnprintf(buf, sizeof(buf), fmt, args);
#else
sprintf(buf, "message incomplete because your OS sucks: %s\n", fmt);
#endif
syslog(LOG_NOTICE, buf);
}
else
{
#ifdef HAVE_VFPRINTF
vfprintf(stderr, fmt, args);
#else
fprintf(stderr, "message incomplete because your OS sucks: %s\n", fmt);
#endif
}
va_end(args);
}
/*
* returns true if the string passed in is an internet address in dotted quad
* notation.
*/
int is_dotted_quad(char *addr)
{
int q[4];
char *p;
int i;
if(sscanf(addr, "%d.%d.%d.%d", &(q[0]), &(q[1]), &(q[2]), &(q[3])) != 4)
{
return(0);
}
if(q[0] > 255 || q[0] < 0 ||
q[1] > 255 || q[1] < 0 ||
q[2] > 255 || q[2] < 0 ||
q[3] > 255 || q[3] < 0)
{
return(0);
}
/* we know there are 3 dots */
p = addr;
if(p != NULL) { p = strchr(p, '.'); p++; }
if(p != NULL) { p = strchr(p, '.'); p++; }
if(p != NULL) { p = strchr(p, '.'); }
for(i=0; *p != '\0' && i<4; i++, p++);
if(*p != '\0')
{
return(0);
}
return(1);
}
void parse_service(char *str)
{
int i;
int width;
for(i=0; i<ARRAY_LEN(services); i++)
{
int j;
for(j=0; j<ARRAY_LEN(services[i].names) && services[i].names[j] != NULL; j++)
{
if(strcmp(services[i].names[j], str) == 0)
{
service = &(services[i]);
return;
}
}
}
fprintf(stderr, "unknown service type: %s\n", str);
fprintf(stderr, "try one of: \n");
width = fprintf(stderr, " ");
for(i=0; i<ARRAY_LEN(services); i++)
{
if(width > 60) { width = fprintf(stderr, "\n ") -1; }
width += fprintf(stderr, "%s ", services[i].names[0]);
}
fprintf(stderr, "\n");
exit(1);
}
int option_handler(int id, char *optarg)
{
#if HAVE_PWD_H && HAVE_GRP_H
struct passwd *pw;
#endif
char *tmp;
int i;
switch(id)
{
case CMD_address:
if(address) { free(address); }
address = strdup(optarg);
dprintf((stderr, "address: %s\n", address));
break;
case CMD_daemon:
options |= OPT_DAEMON;
dprintf((stderr, "daemon mode\n"));
break;
case CMD_debug:
#ifdef DEBUG
options |= OPT_DEBUG;
dprintf((stderr, "debugging on\n"));
#else
fprintf(stderr, "debugging was not enabled at compile time\n");
#endif
break;
case CMD_execute:
#if defined(HAVE_WAITPID) || defined(HAVE_WAIT)
if(post_update_cmd) { free(post_update_cmd); }
post_update_cmd = malloc(strlen(optarg) + 1 + ARGLENGTH + 1);
post_update_cmd_arg = post_update_cmd + strlen(optarg) + 1;
sprintf(post_update_cmd, "%s ", optarg);
dprintf((stderr, "post_update_cmd: %s\n", post_update_cmd));
#else
fprintf(stderr, "command execution not enabled at compile time\n");
exit(1);
#endif
break;
case CMD_foreground:
options |= OPT_FOREGROUND;
dprintf((stderr, "fork()ing off\n"));
break;
case CMD_pid_file:
#if HAVE_GETPID
if(pid_file) { free(pid_file); }
pid_file = strdup(optarg);
dprintf((stderr, "pid file: %s\n", pid_file));
#else
fprintf(stderr, "pid file support not enabled at compile time\n");
#endif
break;
case CMD_host:
if(host) { free(host); }
host = strdup(optarg);
dprintf((stderr, "host: %s\n", host));
break;
case CMD_interface:
#ifdef IF_LOOKUP
if(interface) { free(interface); }
interface = strdup(optarg);
dprintf((stderr, "interface: %s\n", interface));
#else
fprintf(stderr, "interface lookup not enabled at compile time\n");
exit(1);
#endif
break;
case CMD_mx:
if(mx) { free(mx); }
mx = strdup(optarg);
dprintf((stderr, "mx: %s\n", mx));
break;
case CMD_max_interval:
max_interval = get_duration(optarg);
if(max_interval < MIN_MAXINTERVAL)
{
fprintf(stderr, "WARNING: max-interval of %d is too short, using %d\n",
max_interval, MIN_MAXINTERVAL);
max_interval = MIN_MAXINTERVAL;
}
dprintf((stderr, "max_interval: %d\n", max_interval));
break;
case CMD_notify_email:
if(notify_email) { free(notify_email); }
notify_email = strdup(optarg);
dprintf((stderr, "notify_email: %s\n", notify_email));
break;
case CMD_offline:
options |= OPT_OFFLINE;
dprintf((stderr, "offline mode\n"));
break;
case CMD_period:
update_period = get_duration(optarg);
if(update_period < MIN_UPDATE_PERIOD)
{
fprintf(stderr, "WARNING: period of %d is too short, using %d\n",
update_period, MIN_UPDATE_PERIOD);
update_period = MIN_UPDATE_PERIOD;
}
dprintf((stderr, "update_period: %d\n", update_period));
break;
case CMD_resolv_period:
resolv_period = get_duration(optarg);
if(resolv_period < 1)
{
fprintf(stderr, "WARNING: period of %d is too short, using %d\n",
resolv_period, 1);