bin/dbupdate/process.cc
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- process_networkupdate
1 /***************************************
2 $Revision: 1.7 $
3
4 process.cc
5
6 Status: NOT REVIEWED, TESTED
7
8 Author(s): Engin Gunduz
9
10 ******************/ /******************
11 Modification History:
12 engin (01/03/2001) Created.
13 ******************/ /******************
14 Copyright (c) 2001 RIPE NCC
15
16 All Rights Reserved
17
18 Permission to use, copy, modify, and distribute this software and its
19 documentation for any purpose and without fee is hereby granted,
20 provided that the above copyright notice appear in all copies and that
21 both that copyright notice and this permission notice appear in
22 supporting documentation, and that the name of the author not be
23 used in advertising or publicity pertaining to distribution of the
24 software without specific, written prior permission.
25
26 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
27 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
28 AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
29 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
30 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 ***************************************/
33
34
35
36
37
38 #include "dbupdate.h"
39 #include "process.h"
40
41 extern char * copyright_notice;
42 extern char * netupdclientIP;
43
44 extern int count_successful;
45 extern int count_unsuccessful;
46
47 /* process_networkupdate function processes network updates. Since dbupdate is
48 invoked by inetd for networkupdates, we simply read the standard input to get
49 the objects. It must process an object as soon as it reads it from the stdin.
50 That is, there is no need for keeping a linked list of objects, so there
51 won't be any object reordering */
52
53 void process_networkupdate(credentials_struct credentials,
/* [<][>][^][v][top][bottom][index][help] */
54 GHashTable * AUTO_NIC_hdl_hash,
55 char * ack_file_name,
56 GHashTable * ntfy_hash,
57 GHashTable * forw_hash,
58 GHashTable * cross_hash){
59
60
61 GSList *next = NULL;
62 int object_count = 0;
63 char *object = NULL;
64 char * line;
65 int result = 0;
66 ip_addr_t *peerip;
67
68 /* here we will check if the peer is authorised to do networkupdates */
69
70 /* get the IP of the peer. */
71 peerip = (ip_addr_t *)malloc(sizeof(ip_addr_t));
72 SK_getpeerip(0, peerip);
73
74 /* convert it to a char *, for reporting */
75 netupdclientIP = (char *)malloc(64);
76 IP_addr_b2a(peerip, netupdclientIP, 64);
77
78 /* and check if the peer has permission to do networkupdate
79 As the "source" to AA_can_networkupdate we use the first
80 updatable source. Since currently we don't support multiple
81 sources, this is not a problem but when we support it, we must change this.
82 Or, rather, we can simply change AA_can_networkupdate not to ask for
83 a source. This probably also requires changing aaa table of the ripadmin
84 db. */
85 if(!AA_can_networkupdate(peerip, sources[0])){
86
87 printf("\n\n***You are not authorized to do network updates***\n\n");
88 close(0);
89 exit(1);
90
91 }
92
93 /* print the copyright notice (PW_RESP_HEADER) */
94 printf("\n%s\n", copyright_notice);
95 fflush(0);
96
97 line = (char *)malloc(1024);
98
99
100 while(fgets(line, 1023, stdin ) != NULL){
101
102 /* first, if it is a pasword, save it, but do not regard it as an attrib */
103 if(strstr(line, "password:") == line){
104 credentials.password_list = g_slist_append(credentials.password_list,
105 g_strstrip(strdup(line + strlen("password:"))));
106 continue;
107
108 }
109 line = UP_remove_EOLs(line); /* remove '\n's and '\r' first */
110
111 /* remove trailing white space */
112 line = g_strchomp(line);
113
114 if(strlen(line) == 0){/* then, this was an empty line */
115
116 if(object != NULL){
117
118 /* first log the object */
119 UP_log_networkupdate(object, netupdclientIP);
120
121 result = process_object(object, credentials, AUTO_NIC_hdl_hash, ack_file_name,
122 ntfy_hash, forw_hash, cross_hash);
123
124 /* keep a tally */
125 if(result == UP_OK){
126 count_successful++;
127 }else{
128 count_unsuccessful++;
129 }
130
131 free(object);
132 object = NULL;
133
134 }
135
136 }else{
137 if(object == NULL && strlen(line) != 0){
138
139 object = (char *)malloc(strlen(line) + 2);
140 object = strcpy(object, line);
141 object = strcat(object, "\n"); /* add EOL again (we removed it before) */
142
143 }
144 else{
145
146 object = (char *)realloc(object, strlen(object) + strlen(line) + 2);
147 object = strcat(object, line);
148 object = strcat(object, "\n");
149
150 }
151 }
152
153 }
154
155
156 /* now, if at the very and of the input file there wasn't an
157 empty line, we have to add the remaining object in the 'object'
158 variable */
159 if(object != NULL){
160 process_object(object, credentials, AUTO_NIC_hdl_hash, ack_file_name,
161 ntfy_hash, forw_hash, cross_hash);
162 /* keep a tally */
163 if(result == UP_OK){
164 count_successful++;
165 }else{
166 count_unsuccessful++;
167 }
168
169 object = NULL;
170 }
171
172 close(0);
173
174
175 }/* process_networkupdate */
176
177
178
179