bin/dbupdate/process.cc

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

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