bin/dbupdate/process.cc
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- process_networkupdate
1 /***************************************
2 $Revision: 1.6 $
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 /* process_networkupdate function processes network updates. Since dbupdate is
45 invoked by inetd for networkupdates, we simply read the standard input to get
46 the objects. It must process an object as soon as it reads it from the stdin.
47 That is, there is no need for keeping a linked list of objects, so there
48 won't be any object reordering */
49
50 void process_networkupdate(credentials_struct credentials,
/* [<][>][^][v][top][bottom][index][help] */
51 GHashTable * AUTO_NIC_hdl_hash,
52 char * ack_file_name,
53 GHashTable * ntfy_hash,
54 GHashTable * forw_hash,
55 GHashTable * cross_hash){
56
57
58 GSList *next = NULL;
59 int object_count = 0;
60 char *object = NULL;
61 char * line;
62 int result = 0;
63 ip_addr_t *peerip;
64
65 /* here we will check if the peer is authorised to do networkupdates */
66
67 /* get the IP of the peer. */
68 peerip = (ip_addr_t *)malloc(sizeof(ip_addr_t));
69 SK_getpeerip(0, peerip);
70
71 /* convert it to a char *, for reporting */
72 netupdclientIP = (char *)malloc(64);
73 IP_addr_b2a(peerip, netupdclientIP, 64);
74
75 /* and check if the peer has permission to do networkupdate
76 As the "source" to AA_can_networkupdate we use the first
77 updatable source. Since currently we don't support multiple
78 sources, this is not a problem but when we support it, we must change this.
79 Or, rather, we can simply change AA_can_networkupdate not to ask for
80 a source. This probably also requires changing aaa table of the ripadmin
81 db. */
82 if(!AA_can_networkupdate(peerip, sources[0])){
83
84 printf("\n\n***You are not authorized to do network updates***\n\n");
85 close(0);
86 exit(1);
87
88 }
89
90 /* print the copyright notice (PW_RESP_HEADER) */
91 printf("\n%s\n", copyright_notice);
92 fflush(0);
93
94 line = (char *)malloc(1024);
95
96
97 while(fgets(line, 1023, stdin ) != NULL){
98
99 /* first, if it is a pasword, save it, but do not regard it as an attrib */
100 if(strstr(line, "password:") == line){
101 credentials.password_list = g_slist_append(credentials.password_list,
102 g_strstrip(strdup(line + strlen("password:"))));
103 continue;
104
105 }
106 line = UP_remove_EOLs(line); /* remove '\n's and '\r' first */
107
108 /* remove trailing white space */
109 line = g_strchomp(line);
110
111 if(strlen(line) == 0){/* then, this was an empty line */
112
113 if(object != NULL){
114
115 /* first log the object */
116 UP_log_networkupdate(object, netupdclientIP);
117
118 process_object(object, credentials, AUTO_NIC_hdl_hash, ack_file_name,
119 ntfy_hash, forw_hash, cross_hash);
120 free(object);
121 object = NULL;
122
123 }
124
125 }else{
126 if(object == NULL && strlen(line) != 0){
127
128 object = (char *)malloc(strlen(line) + 2);
129 object = strcpy(object, line);
130 object = strcat(object, "\n"); /* add EOL again (we removed it before) */
131
132 }
133 else{
134
135 object = (char *)realloc(object, strlen(object) + strlen(line) + 2);
136 object = strcat(object, line);
137 object = strcat(object, "\n");
138
139 }
140 }
141
142 }
143
144
145 /* now, if at the very and of the input file there wasn't an
146 empty line, we have to add the remaining object in the 'object'
147 variable */
148 if(object != NULL){
149 process_object(object, credentials, AUTO_NIC_hdl_hash, ack_file_name,
150 ntfy_hash, forw_hash, cross_hash);
151 object = NULL;
152 }
153
154 close(0);
155
156
157 }/* process_networkupdate */
158
159
160
161