bin/dbupdate/process.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. process_networkupdate

   1 /***************************************
   2   $Revision: 1.2 $
   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 char *object = NULL;
  62 char * line;
  63 int result = 0;
  64 ip_addr_t *peerip;
  65 
  66     /* here we will check if the peer is authorised to do networkupdates */
  67 
  68     /* get the IP of the peer. */
  69     peerip = (ip_addr_t *)malloc(sizeof(ip_addr_t));
  70     SK_getpeerip(0, peerip);
  71 
  72     /* convert it to a char *, for reporting */
  73     netupdclientIP = (char *)malloc(64);
  74     IP_addr_b2a(peerip, netupdclientIP, 64);
  75    
  76     /* and check if the peer has permission to do networkupdate 
  77        As the "source" to AA_can_networkupdate we use the first
  78        updatable source. Since currently we don't support multiple 
  79        sources, this is not a problem but when we support it, we must change this.
  80        Or, rather, we can simply change AA_can_networkupdate not to ask for
  81        a source. This probably also requires changing aaa table of the ripadmin
  82        db.  */
  83     if(!AA_can_networkupdate(peerip, sources[0])){
  84       
  85       printf("\n\n***You are not authorized to do network updates***\n\n");
  86       close(0);
  87       exit(1);
  88 
  89     }
  90   
  91     /* print the copyright notice (PW_RESP_HEADER) */
  92     printf("\n%s\n", copyright_notice);
  93     fflush(0);
  94 
  95     line = (char *)malloc(1024);
  96 
  97   
  98     while(fgets(line, 1023, stdin ) != NULL){
  99 
 100       /* first, if it is a pasword, save it, but do not regard it as an attrib */ 
 101       if(strstr(line, "password:") == line){
 102         credentials.password_list = g_slist_append(credentials.password_list, 
 103                                       g_strstrip(strdup(line + strlen("password:"))));
 104         continue;
 105 
 106       }
 107       line = UP_remove_EOLs(line); /* remove '\n's and '\r' first */
 108 
 109       /* remove trailing white space */
 110       line = g_strchomp(line); 
 111 
 112       if(strlen(line) == 0){/* then, this was an empty line */
 113 
 114         if(object != NULL){
 115 
 116            /* first log the object */
 117            UP_log_networkupdate(object, netupdclientIP);
 118 
 119            result = process_object(object, credentials, AUTO_NIC_hdl_hash, ack_file_name,
 120                       ntfy_hash, forw_hash, cross_hash);
 121            
 122            /* keep a tally */
 123            if(result == UP_OK){
 124              count_successful++;
 125            }else{
 126              count_unsuccessful++;
 127            }
 128            
 129            free(object);
 130            object = NULL;
 131 
 132         }
 133 
 134       }else{
 135         if(object == NULL && strlen(line) != 0){
 136 
 137           object = (char *)malloc(strlen(line) + 2);
 138           object = strcpy(object, line);
 139           object = strcat(object, "\n"); /* add EOL again (we removed it before) */
 140 
 141         }
 142         else{
 143 
 144           object = (char *)realloc(object, strlen(object) + strlen(line) + 2);
 145           object = strcat(object, line);
 146           object = strcat(object, "\n");
 147 
 148         }
 149       }
 150       
 151     }
 152 
 153 
 154     /* now, if at the very and of the input file there wasn't an 
 155        empty line, we have to add the remaining object in the 'object'
 156        variable */
 157     if(object != NULL){
 158        process_object(object, credentials, AUTO_NIC_hdl_hash, ack_file_name,
 159                       ntfy_hash, forw_hash, cross_hash);
 160        /* keep a tally */
 161        if(result == UP_OK){
 162          count_successful++;
 163        }else{
 164          count_unsuccessful++;
 165        }
 166        
 167        object = NULL;
 168     }
 169 
 170     close(0);
 171 
 172   
 173 }/* process_networkupdate */
 174 
 175 
 176 
 177 

/* [<][>][^][v][top][bottom][index][help] */