Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 248758 | Differences between
and this patch

Collapse All | Expand All

(-)noip-2.1.9.patched/noip2.c (-46 / +243 lines)
Lines 112-117 Link Here
112
	+	instances were not diplayed due to stderr being closed
112
	+	instances were not diplayed due to stderr being closed
113
	+	added version number into shared mem and -S display
113
	+	added version number into shared mem and -S display
114
114
115
	+	November 2008 (johna)	still version 2.1.8
116
	+       reworked forced update code to use 'wget' and the
117
        +       hostactivate.php script at www.no-ip.com
118
	+	added check of returned IP address in get_our_visble_IP_addr
119
	+ 	hardened GetNextLine to prevent possible buffer overflow
120
121
	+	November 2008 (johna)  version 2.1.9
122
	+	hardened force_update() to prevent possible buffer overflow
123
	+	hardened autoconf() the same way
124
	+	patch suggested by xenomuta@phreaker.net
125
115
*/			
126
*/			
116
/////////////////////////////////////////////////////////////////////////////                                            
127
/////////////////////////////////////////////////////////////////////////////                                            
117
128
Lines 166-173 Link Here
166
#define DEBUG
177
#define DEBUG
167
178
168
#define ENCRYPT			1
179
#define ENCRYPT			1
180
#define FORCE_UPDATE		0
169
181
170
#undef MAX
171
#define MAX(x,y)		(((x)>(y))?(x):(y))
182
#define MAX(x,y)		(((x)>(y))?(x):(y))
172
183
173
#define READ_TIMEOUT		90
184
#define READ_TIMEOUT		90
Lines 181-190 Link Here
181
192
182
193
183
#define NOIP_NAME		"dynupdate.no-ip.com"
194
#define NOIP_NAME		"dynupdate.no-ip.com"
195
#define UPD_NAME		"www.no-ip.com"
196
#define UPD_SCRIPT		"hostactive.php"
184
#define NOIP_IP_SCRIPT	"ip1.dynupdate.no-ip.com"
197
#define NOIP_IP_SCRIPT	"ip1.dynupdate.no-ip.com"
185
#define CLIENT_IP_PORT		8245
198
#define CLIENT_IP_PORT		8245
186
199
187
#define VERSION			"2.1.7"
200
#define VERSION			"2.1.9"
188
#define USER_AGENT		"User-Agent: Linux-DUC/"VERSION
201
#define USER_AGENT		"User-Agent: Linux-DUC/"VERSION
189
#define SETTING_SCRIPT		"settings.php?"
202
#define SETTING_SCRIPT		"settings.php?"
190
#define USTRNG			"username="
203
#define USTRNG			"username="
Lines 218-223 Link Here
218
#define NODNSGROUP		"@@NO_GROUP@@"
231
#define NODNSGROUP		"@@NO_GROUP@@"
219
#define HOST			1
232
#define HOST			1
220
#define GROUP			2
233
#define GROUP			2
234
#define DOMAIN			3
221
#ifndef PREFIX
235
#ifndef PREFIX
222
  #define PREFIX		"/usr/local"
236
  #define PREFIX		"/usr/local"
223
#endif
237
#endif
Lines 232-237 Link Here
232
#define NOIP_KEY		0x50494f4e
246
#define NOIP_KEY		0x50494f4e
233
#define SHMEM_SIZE		(MAX_INSTANCE * sizeof(struct INSTANCE))
247
#define SHMEM_SIZE		(MAX_INSTANCE * sizeof(struct INSTANCE))
234
#define DEFAULT_NAT_INTERVAL	30
248
#define DEFAULT_NAT_INTERVAL	30
249
#define WGET_PGM		"/usr/bin/wget"
235
250
236
#define SPACE			' '
251
#define SPACE			' '
237
#define EQUALS			'='
252
#define EQUALS			'='
Lines 269-274 Link Here
269
#define BADCONFIG4		-14
284
#define BADCONFIG4		-14
270
#define BADCONFIG5		-15
285
#define BADCONFIG5		-15
271
#define BADCONFIG6		-16
286
#define BADCONFIG6		-16
287
#define BADACTIVATE		-20
272
288
273
#define CMSG01	"Can't locate configuration file %s. (Try -c). Ending!\n" 
289
#define CMSG01	"Can't locate configuration file %s. (Try -c). Ending!\n" 
274
#define CMSG02	"'%s' is a badly constructed configuration file. Ending!\n" 
290
#define CMSG02	"'%s' is a badly constructed configuration file. Ending!\n" 
Lines 312-317 Link Here
312
#define CMSG40	"Do you wish to run something at successful update?[N] (y/N)  "
328
#define CMSG40	"Do you wish to run something at successful update?[N] (y/N)  "
313
#define CMSG40a	"Please enter the script/program name  "
329
#define CMSG40a	"Please enter the script/program name  "
314
#define CMSG41	"Exec path unreadable in '%s'. Ending!\n" 
330
#define CMSG41	"Exec path unreadable in '%s'. Ending!\n" 
331
#define CMSG42  "Can't get our visible IP address from %s"
332
#define CMSG43  "Invalid domain name '%s'"
333
#define CMSG44  "Invalid host name '%s'"
315
#define CMSG99	"\nThis client has expired.  Please go to http://www.no-ip.com/downloads.php"  
334
#define CMSG99	"\nThis client has expired.  Please go to http://www.no-ip.com/downloads.php"  
316
#define CMSG99a	"to get our most recent version.\n"  
335
#define CMSG99a	"to get our most recent version.\n"  
317
336
Lines 342-348 Link Here
342
int	reqnum			=	0;
361
int	reqnum			=	0;
343
int	prompt_for_executable	=	1;
362
int	prompt_for_executable	=	1;
344
int	shm_dump_active		=	0;
363
int	shm_dump_active		=	0;
345
int	Force_Update		=	0;	// force initial action
364
int	Force_Update		=	FORCE_INTERVAL;
346
int	dummy			=	0;
365
int	dummy			=	0;
347
void	*shmaddr		=	NULL;
366
void	*shmaddr		=	NULL;
348
char	*program		=	NULL;
367
char	*program		=	NULL;
Lines 447-452 Link Here
447
466
448
///////////////////////////////////////////////////////////////////////////
467
///////////////////////////////////////////////////////////////////////////
449
void	process_options(int argc, char *argv[]);
468
void	process_options(int argc, char *argv[]);
469
void	update_handler(int signum);
450
void	alarm_handler(int signum);
470
void	alarm_handler(int signum);
451
void	sigchld_handler(int signum);
471
void	sigchld_handler(int signum);
452
void	exit_handler(int signum);
472
void	exit_handler(int signum);
Lines 456-461 Link Here
456
void	save_IP();
476
void	save_IP();
457
void	dump_shm(struct shmid_ds *d);
477
void	dump_shm(struct shmid_ds *d);
458
int	get_shm_info();
478
int	get_shm_info();
479
int	validate_IP_addr(char *src, char *dest);
459
void	get_our_visible_IPaddr(char *dest);
480
void	get_our_visible_IPaddr(char *dest);
460
void	getip(char *dest, char *device);
481
void	getip(char *dest, char *device);
461
int	run_as_background();
482
int	run_as_background();
Lines 474-479 Link Here
474
ushort	chksum(char *buf, unsigned int size);
495
ushort	chksum(char *buf, unsigned int size);
475
void	dump_buffer(int x);
496
void	dump_buffer(int x);
476
int	dynamic_update();
497
int	dynamic_update();
498
int	validate_name(int flag, char *name);
499
int	force_update();
477
int	handle_dynup_error(int error_code);
500
int	handle_dynup_error(int error_code);
478
int	handle_config_error(int err_code);
501
int	handle_config_error(int err_code);
479
void	*Malloc(int size);
502
void	*Malloc(int size);
Lines 584-589 Link Here
584
	if (background) {
607
	if (background) {
585
	    sig.sa_handler = (void *)wake_handler;
608
	    sig.sa_handler = (void *)wake_handler;
586
	    sigaction(SIGUSR1,&sig,NULL);
609
	    sigaction(SIGUSR1,&sig,NULL);
610
	    sig.sa_handler = update_handler;
611
	    sigaction(SIGUSR2,&sig,NULL);
587
	    sig.sa_handler = exit_handler;
612
	    sig.sa_handler = exit_handler;
588
	    sigaction(SIGINT,&sig,NULL);
613
	    sigaction(SIGINT,&sig,NULL);
589
	    sigaction(SIGTERM,&sig,NULL);
614
	    sigaction(SIGTERM,&sig,NULL);
Lines 613-619 Link Here
613
		shmdt(shmaddr);			// done with our shared memory
638
		shmdt(shmaddr);			// done with our shared memory
614
		return FATALERR;
639
		return FATALERR;
615
	    }
640
	    }
616
	    strcpy(my_instance->Last_IP_Addr, IPaddress);
641
	    strncpy(my_instance->Last_IP_Addr, IPaddress, IPLEN);
617
	}
642
	}
618
	save_IP();
643
	save_IP();
619
	free(new_config);
644
	free(new_config);
Lines 747-752 Link Here
747
	return;
772
	return;
748
}
773
}
749
///////////////////////////////////////////////////////////////////////////
774
///////////////////////////////////////////////////////////////////////////
775
void update_handler(int signum)	// entered on SIGUSR2
776
{
777
	Force_Update = -1;
778
}
779
///////////////////////////////////////////////////////////////////////////
750
void alarm_handler(int signum)	// entered on SIGALRM
780
void alarm_handler(int signum)	// entered on SIGALRM
751
{
781
{
752
	timed_out = 1;
782
	timed_out = 1;
Lines 956-962 Link Here
956
			}
986
			}
957
		    }
987
		    }
958
		    if (!background && *IPaddress) { // update running daemon
988
		    if (!background && *IPaddress) { // update running daemon
959
			strcpy(is->Last_IP_Addr, IPaddress);
989
			strncpy(is->Last_IP_Addr, IPaddress, IPLEN);
960
			continue;
990
			continue;
961
		    }
991
		    }
962
		    Msg("Configuration '%s' already in use", is->cfilename);
992
		    Msg("Configuration '%s' already in use", is->cfilename);
Lines 983-990 Link Here
983
int run_as_background()
1013
int run_as_background()
984
{
1014
{
985
	int	x, delay;
1015
	int	x, delay;
986
	int	time_to_update;
987
	char	*err_string;
1016
	char	*err_string;
1017
	static int startup = 1;
988
1018
989
	x = fork();
1019
	x = fork();
990
	switch (x) {
1020
	switch (x) {
Lines 999-1005 Link Here
999
		if (get_shm_info() == FATALERR)	
1029
		if (get_shm_info() == FATALERR)	
1000
		    return FATALERR;
1030
		    return FATALERR;
1001
		log2syslog++;
1031
		log2syslog++;
1002
		fclose(stderr);
1032
		if (log2syslog > 0)
1033
		    fclose(stderr);
1003
		fclose(stdout);
1034
		fclose(stdout);
1004
		fclose(stdin);
1035
		fclose(stdin);
1005
		syslog(LOG_INFO, "v%s daemon started%s\n", 
1036
		syslog(LOG_INFO, "v%s daemon started%s\n", 
Lines 1010-1047 Link Here
1010
			get_our_visible_IPaddr(IPaddress);
1041
			get_our_visible_IPaddr(IPaddress);
1011
		    else
1042
		    else
1012
			getip(IPaddress, device);
1043
			getip(IPaddress, device);
1044
		    if (startup) {
1045
			startup = 0;
1046
			my_instance->Last_IP_Addr[0] =  '0';// force  check
1047
		    }
1013
#ifdef DEBUG
1048
#ifdef DEBUG
1014
		    if (my_instance->debug)  {
1049
		    if (my_instance->debug)  {
1015
		        Msg("! Last_IP_Addr = %s, IP = %s",my_instance->Last_IP_Addr, IPaddress);
1050
		        Msg("! Last_IP_Addr = %s, IP = %s",my_instance->Last_IP_Addr, IPaddress);
1051
#if FORCE_UPDATE
1016
			Msg("Force_Update == %d\n", Force_Update);
1052
			Msg("Force_Update == %d\n", Force_Update);
1053
#endif
1017
		    }
1054
		    }
1018
#endif
1055
#endif
1019
		    time_to_update = 0;
1020
		    if (*IPaddress) { 
1056
		    if (*IPaddress) { 
1021
			if (strcmp(IPaddress, my_instance->Last_IP_Addr) ||
1057
			if (strcmp(IPaddress, my_instance->Last_IP_Addr)) {
1022
				(Force_Update <= 0))
1058
			    if (dynamic_update() == SUCCESS) 
1023
			    time_to_update = 1;
1059
				strncpy(my_instance->Last_IP_Addr, IPaddress,
1024
		    } else {	// make sure we don't lose force update trigger
1060
									IPLEN);
1025
			if (Force_Update <= 0)
1061
			    if (connect_fail)
1026
			    Force_Update = my_instance->interval;
1062
				delay = MAX(300, delay); // wait at least 5 minutes more
1027
		    }
1063
			    *IPaddress = 0;
1028
		    if (time_to_update) {
1064
			}
1029
			if (dynamic_update() == SUCCESS) 
1030
			    strcpy(my_instance->Last_IP_Addr, IPaddress);
1031
			else		// don't lose forced update trigger
1032
			    Force_Update = MAX(Force_Update, 
1033
							my_instance->interval);
1034
			if (connect_fail)
1035
			    delay = MAX(300, delay); // wait at least 5 minutes more
1036
			*IPaddress = 0;
1037
		    }
1065
		    }
1038
		    if (Force_Update <= 0) {
1066
#if FORCE_UPDATE
1039
			// reset to max 
1067
		    if (Force_Update < 0) {
1040
			Force_Update = FORCE_INTERVAL;
1068
			if (force_update() == SUCCESS)
1041
		    } else {
1069
			    Force_Update = FORCE_INTERVAL;
1042
			// one time quanta closer to update trigger
1070
		    } else {	// one time quanta closer to update trigger
1043
			Force_Update -= my_instance->interval;
1071
			Force_Update -= my_instance->interval;
1044
		    }
1072
		    }
1073
#endif
1045
		    if (background)	// signal may have reset this!
1074
		    if (background)	// signal may have reset this!
1046
			Sleep(delay);
1075
			Sleep(delay);
1047
		}
1076
		}
Lines 1479-1484 Link Here
1479
	return SUCCESS;
1508
	return SUCCESS;
1480
}
1509
}
1481
///////////////////////////////////////////////////////////////////////////
1510
///////////////////////////////////////////////////////////////////////////
1511
int validate_IP_addr(char *src, char *dest)
1512
{
1513
	char	*p;
1514
	int	i, octet;
1515
1516
	octet = atoi(src);
1517
	if ((octet > 255) || (octet < 0))
1518
	    return 0;				// bad octet
1519
	if ((p = strchr(src, '.')) != NULL) {
1520
	    octet = atoi(++p);
1521
	    if ((octet > 255) || (octet < 0))
1522
		return 0;			// bad octet
1523
	    if ((p = strchr(p, '.')) != NULL) {
1524
		octet = atoi(++p);
1525
		if ((octet > 255) || (octet < 0))
1526
		    return 0;			// bad octet
1527
		if ((p = strchr(p, '.')) != NULL) {
1528
		    octet = atoi(++p);
1529
		    if ((octet <= 255) && (octet >= 0)) {
1530
			for (i=0; i<3; i++)
1531
			    if (!isdigit(p[i]))
1532
				break;
1533
			p[i] = 0;			// NULL terminate
1534
			strncpy(dest, src, IPLEN);
1535
			return 1;			// valid IP address
1536
		    }
1537
		}
1538
	    }
1539
	}
1540
	return 0;				// not enough dots
1541
}
1542
///////////////////////////////////////////////////////////////////////////
1482
void get_our_visible_IPaddr(char *dest)
1543
void get_our_visible_IPaddr(char *dest)
1483
{
1544
{
1484
	int	x;
1545
	int	x;
Lines 1497-1503 Link Here
1497
	    } else {
1558
	    } else {
1498
		close(socket_fd);
1559
		close(socket_fd);
1499
		if ((p = strrchr(buffer,'\n'))) {// get end of penultimate line
1560
		if ((p = strrchr(buffer,'\n'))) {// get end of penultimate line
1500
		    strcpy(dest, ++p);  	// address on next line
1561
		    if (!validate_IP_addr(++p, dest))// address on next line
1562
			Msg(CMSG42, NOIP_IP_SCRIPT); 
1501
#ifdef DEBUG
1563
#ifdef DEBUG
1502
		    if (my_instance ? my_instance->debug : debug)
1564
		    if (my_instance ? my_instance->debug : debug)
1503
			fprintf(stderr,"! Our NAT IP address is %s\n", dest);
1565
			fprintf(stderr,"! Our NAT IP address is %s\n", dest);
Lines 1506-1512 Link Here
1506
		return;				// NORMAL EXIT
1568
		return;				// NORMAL EXIT
1507
	    } 
1569
	    } 
1508
	}
1570
	}
1509
	Msg("Can't get our visible IP address from %s", NOIP_IP_SCRIPT); 
1571
	Msg(CMSG42, NOIP_IP_SCRIPT); 
1510
	return;
1572
	return;
1511
}
1573
}
1512
///////////////////////////////////////////////////////////////////////////
1574
///////////////////////////////////////////////////////////////////////////
Lines 1533-1538 Link Here
1533
	}    
1595
	}    
1534
	// set up text for web page update
1596
	// set up text for web page update
1535
	bdecode(request, buffer);
1597
	bdecode(request, buffer);
1598
	// IPaddress has already been validated as to length and contents
1536
	sprintf(tbuf, "&ip=%s", IPaddress);
1599
	sprintf(tbuf, "&ip=%s", IPaddress);
1537
	strcat(buffer, tbuf);
1600
	strcat(buffer, tbuf);
1538
	// use latter half of big buffer
1601
	// use latter half of big buffer
Lines 1568-1574 Link Here
1568
		*p++ = 0;		// now p points at return code
1631
		*p++ = 0;		// now p points at return code
1569
		i = atoi(p);
1632
		i = atoi(p);
1570
		if (is_group) {
1633
		if (is_group) {
1571
		    sprintf(gname, "group[%s]", ourname);
1634
		    snprintf(gname, LINELEN-1, "group[%s]", ourname);
1572
		    ourname = gname;
1635
		    ourname = gname;
1573
		}
1636
		}
1574
		response++;
1637
		response++;
Lines 1594-1599 Link Here
1594
		    Msg("Can't fork (%s) to run %s", strerror(errno), buffer);
1657
		    Msg("Can't fork (%s) to run %s", strerror(errno), buffer);
1595
		    exit(1);
1658
		    exit(1);
1596
		case 0:			// child
1659
		case 0:			// child
1660
		    // IPaddress has already been validated as to length and contents
1597
		    sprintf(ipbuf, "%s", IPaddress);
1661
		    sprintf(ipbuf, "%s", IPaddress);
1598
		    p = strrchr(buffer, '/');
1662
		    p = strrchr(buffer, '/');
1599
		    if (p)
1663
		    if (p)
Lines 1700-1705 Link Here
1700
	    case WRITEFAIL:
1764
	    case WRITEFAIL:
1701
		Msg("Write to %s failed (%s)", NOIP_NAME, err_string); 
1765
		Msg("Write to %s failed (%s)", NOIP_NAME, err_string); 
1702
		break;
1766
		break;
1767
	    case BADACTIVATE:
1768
		Msg("Can't activate host at %s", UPD_NAME); 
1769
		break;
1703
	    default:
1770
	    default:
1704
		Msg("Unknown error %d trying to set %s at %s.", 
1771
		Msg("Unknown error %d trying to set %s at %s.", 
1705
						error_code, ourname, NOIP_NAME);
1772
						error_code, ourname, NOIP_NAME);
Lines 1913-1919 Link Here
1913
{
1980
{
1914
	char	tbuf[LINELEN];
1981
	char	tbuf[LINELEN];
1915
	
1982
	
1916
	sprintf(tbuf, "&%s[]=%s", (kind==HOST) ? "h" : "g", p);
1983
	snprintf(tbuf, LINELEN-1, "&%s[]=%s", (kind==HOST) ? "h" : "g", p);
1917
	strcat(buffer, tbuf);
1984
	strcat(buffer, tbuf);
1918
	reqnum++;
1985
	reqnum++;
1919
	return strlen(buffer);
1986
	return strlen(buffer);
Lines 1990-1996 Link Here
1990
//////////////////////////////////////////////////////////////////////////
2057
//////////////////////////////////////////////////////////////////////////
1991
void SkipHeaders()
2058
void SkipHeaders()
1992
{
2059
{
1993
	char *p = &buffer[offset];
2060
	char *p;
2061
2062
	// global offset into buffer, set here and used only by GetNextLine !
2063
	offset = 0;
2064
2065
	// position after first blank line 
2066
	p = buffer;
1994
	for(; *p; p++) {
2067
	for(; *p; p++) {
1995
		if(strncmp(p, "\r\n\r\n", 4) == 0) {
2068
		if(strncmp(p, "\r\n\r\n", 4) == 0) {
1996
			offset += 4;
2069
			offset += 4;
Lines 2005-2028 Link Here
2005
{
2078
{
2006
        char    *p = &buffer[offset];
2079
        char    *p = &buffer[offset];
2007
        char    *q = dest;
2080
        char    *q = dest;
2081
	char	*z = &dest[LINELEN-1];
2008
2082
2009
        while (*p && (*p <= ' ')) {     // despace & ignore blank lines
2083
        while (*p && (*p <= ' ')) {     // despace & ignore blank lines
2010
            p++;
2084
            p++;
2011
            offset++;
2085
            offset++;
2012
        }
2086
        }
2013
        while (*p) {
2087
        while ((*p) && (q < z)) {
2014
            *q++ = *p;
2088
            *q++ = (*p) & 0x7f;		// ASCII charset for text
2015
            offset++;
2089
            offset++;
2016
            if (*p == '\n')  {
2090
            if (*p == '\n')  {
2017
                *q = 0;
2091
                *q = 0;
2018
//fprintf(stderr, "LINE = %s", dest);
2092
//fprintf(stderr, "LINE = %s", dest);
2019
                return 1;
2093
                return 1;		// we have a line
2020
            } else
2094
            } else
2021
		p++;
2095
		p++;
2022
        }
2096
        }
2023
	if (q > dest)
2097
	if (q > dest) {			// newline not found
2024
	    return 1;
2098
	    if (q == z)
2025
        return 0;
2099
		q--;			// backup for newline and null
2100
	    *q++ = '\n';		// add '\n' 
2101
	    *q = 0;			// and null
2102
	    return 1;			// we have a line
2103
	}
2104
        return 0;			// no line available
2105
}
2106
///////////////////////////////////////////////////////////////////////////
2107
int force_update()
2108
{
2109
	int	x, found, retcode;
2110
	FILE	*pfd;
2111
	char	*l, *p, *q, domain[LINELEN], host[LINELEN];
2112
        char    ourbuffer[BIGBUFLEN], line[LINELEN], encline[2 * LINELEN];
2113
	
2114
	retcode = SUCCESS;
2115
	bdecode(request, buffer);
2116
	l = strchr(buffer, '=') + 1;		// point at login name
2117
	p = strchr(l, '&');
2118
	*p = 0;                                 // terminate it
2119
	p += 6;					// step over null and 'pass='
2120
	q = strchr(p, '&');
2121
	*q = 0;					// terminate password
2122
        sprintf(line, "%s%s%s%s", USTRNG, l, PWDSTRNG, p);
2123
        bencode(line, encline);
2124
2125
	if ((x = Connect(port_to_use)) != SUCCESS) {
2126
	    handle_dynup_error(x);
2127
	    return x;
2128
	}    
2129
	// get the name list
2130
        sprintf(buffer, "GET http://%s/%s%s%s HTTP/1.0\r\n%s\r\n\r\n",
2131
                NOIP_NAME, SETTING_SCRIPT, REQUEST, encline, USER_AGENT);
2132
        if ((x = converse_with_web_server()) <= 0) {
2133
            handle_dynup_error(x);
2134
            return x;
2135
        }
2136
2137
	SkipHeaders();
2138
        while (GetNextLine(line)) {
2139
            p = line;
2140
            if (strncmp(p, "<domain", 7) == 0)  {
2141
		p = strstr(line, "name=") + 6;
2142
		if (p == NULL) {
2143
		    Msg(CMSG44, p);
2144
		    continue;
2145
		}
2146
		q = strchr(p, '"');
2147
		if (q == NULL) {
2148
		    Msg(CMSG44, p);
2149
		    continue;
2150
		}
2151
		*q = 0;
2152
		if (!validate_name(DOMAIN, p)) {
2153
		    Msg(CMSG43, p);
2154
		    continue;
2155
		}
2156
		snprintf(domain, LINELEN-1, "%s", p);
2157
		continue;
2158
	    }
2159
            if (strncmp(p, "<host", 5) == 0)  {
2160
		p = strstr(line, "name=") + 6;
2161
		if (p == NULL) {
2162
		    Msg(CMSG44, p);
2163
		    continue;
2164
		}
2165
		q = strchr(p, '"');
2166
		if (q == NULL) {
2167
		    Msg(CMSG44, p);
2168
		    continue;
2169
		}
2170
		*q = 0;
2171
		if (!validate_name(HOST, p)) {
2172
		    Msg(CMSG44, p);
2173
		    continue;
2174
		}
2175
		snprintf(host, LINELEN-1, "%s", p);
2176
		// set up web page update command using wget
2177
		sprintf(ourbuffer, 
2178
		    "%s -q -O - 'http://%s/%s?host=%s&domain=%s'", 
2179
			WGET_PGM, UPD_NAME, UPD_SCRIPT, host, domain);
2180
#ifdef DEBUG
2181
		if (my_instance->debug) 
2182
		    Msg("> %s\n", ourbuffer);	// display the command
2183
#endif
2184
		// send wget command
2185
		pfd = popen(ourbuffer, "r");
2186
		found = 0;
2187
		while (fgets(ourbuffer, BIGBUFLEN, pfd)) {
2188
#ifdef DEBUG
2189
		    if (my_instance->debug) 
2190
			Msg("> %s\n", ourbuffer);   // display the line
2191
#endif
2192
		    if (strstr(ourbuffer, "Update Successful!!")) {
2193
			found = 1;
2194
			syslog(LOG_INFO, "Activation of host %s.%s succeeded", 
2195
								host, domain);
2196
			break;
2197
		    }
2198
		}
2199
		pclose(pfd);
2200
		if (!found) 
2201
		    syslog(LOG_INFO, "Can't activate host %s.%s",host, domain);
2202
	    }
2203
        }
2204
	close(socket_fd);
2205
	return retcode;
2206
}
2207
///////////////////////////////////////////////////////////////////////////
2208
int validate_name(int flag, char *name)
2209
{
2210
	char	 *p;
2211
	int	x;
2212
2213
	if (flag == DOMAIN)
2214
	    x = '.';			// add the dot for domains
2215
	else
2216
	    x = '-';			// just re-use the hyphen for hosts
2217
	for (p=name; *p; p++) {
2218
	    if (isalnum(*p) || (*p == '-') || (*p == x))
2219
		continue;
2220
	    return 0;			// invalid char
2221
	}
2222
	return 1;
2026
}
2223
}
2027
///////////////////////////////////////////////////////////////////////////
2224
///////////////////////////////////////////////////////////////////////////
2028
void url_encode(char *p_in, char *p_out)
2225
void url_encode(char *p_in, char *p_out)
Lines 2264-2270 Link Here
2264
	int	x, xfd;
2461
	int	x, xfd;
2265
	int	a, b, c;
2462
	int	a, b, c;
2266
        FILE    *fd;
2463
        FILE    *fd;
2267
        char    *p, *q, line[LINELEN], encline[2 * LINELEN], *pos;
2464
        char    *p, line[LINELEN], encline[2 * LINELEN], *pos;
2268
	char    internal_ip[IPLEN];
2465
	char    internal_ip[IPLEN];
2269
	char    external_ip[IPLEN];
2466
	char    external_ip[IPLEN];
2270
        struct SETTINGS *s;
2467
        struct SETTINGS *s;
Lines 2311-2320 Link Here
2311
	}
2508
	}
2312
        p = buffer;
2509
        p = buffer;
2313
        if ((*p >= '0') && (*p <= '9')) {	// extract IP address
2510
        if ((*p >= '0') && (*p <= '9')) {	// extract IP address
2314
            q = external_ip;
2511
	    if (!validate_IP_addr(buffer, external_ip)) {
2315
            while (((*p >= '0') && (*p <= '9')) || (*p == '.'))
2512
		Msg(CMSG44, p);
2316
                *q++ = *p++;
2513
		exit(1);
2317
	    *q = 0;
2514
	    }
2318
        }
2515
        }
2319
#ifdef DEBUG
2516
#ifdef DEBUG
2320
	if (debug)
2517
	if (debug)
Lines 2519-2522 Link Here
2519
		fprintf(stderr, "%s\n", errmsg);
2716
		fprintf(stderr, "%s\n", errmsg);
2520
}
2717
}
2521
/////////////////////////////////////////////////////////////////////////////
2718
/////////////////////////////////////////////////////////////////////////////
2522
2719
/////////////////////////////////////////////////////////////////////////////

Return to bug 248758