Beispiel #1
0
ProviderRegister *newProviderRegister()
{
   FILE *in;
   char *dir,*provuser = NULL;
   char fin[1024], *stmt = NULL;
   ProviderInfo *info = NULL;
   int err = 0, n = 0, i;
   CntlVals rv;
   int id=0;
   int provSFCB,provuid=-1;
   int interopFound=0;
   struct passwd *passwd;

   ProviderRegister *br = (ProviderRegister *) malloc(sizeof(ProviderRegister) +
                                                      sizeof(ProviderBase));
   ProviderBase *bb = (ProviderBase *) (br + 1);
   
   setupControl(configfile);
   
   // Get/check provider user info
   if (getControlBool("providerDefaultUserSFCB",&provSFCB)) {
     provSFCB = 1;
   } 
   if (provSFCB) {
     // This indicates that we should use the SFCB user by default
     provuid = -1;
   } else {
      if (getControlChars("providerDefaultUser",&provuser)) {
        provuid = -1;
      } else {
        errno=0;
        passwd=getpwnam(provuser);
        if (passwd) {
            provuid=passwd->pw_uid;
        } else {
            mlogf(M_ERROR,M_SHOW,"--- Couldn't find username %s requested in SFCB config file. Errno: %d\n",provuser,errno);
            err=1;
        }
      }
    }


   if (getControlChars("registrationDir",&dir)) {
     dir = "/var/lib/sfcb/registration";
   }

   strcpy(fin, dir);
   strcat(fin, "/providerRegister");
   in = fopen(fin, "r");
   if (in == NULL) 
      mlogf(M_ERROR,M_SHOW, "--- %s not found\n", fin);
      
   else {

      br->hdl = bb;
      br->ft = ProviderRegisterFT;
      bb->fn = strdup(fin);
      bb->ht = UtilFactory->newHashTable(61,
                  UtilHashTable_charKey | UtilHashTable_ignoreKeyCase);

      while (fgets(fin, 1024, in)) {
         n++;
         if (stmt) free(stmt);
         stmt = strdup(fin);
         switch (cntlParseStmt(fin, &rv)) {
         case 0:
            mlogf(M_ERROR,M_SHOW,"--- registration statement not recognized: \n\t%d: %s\n", n,stmt);
            err = 1;
            break;
         case 1:
            if (info) {
               if (classProvInfoPtr==NULL) {
                  if (strcmp(info->className,"$ClassProvider$")==0) classProvInfoPtr=info;
               }   
               else if (defaultProvInfoPtr==NULL) {
                  if (strcmp(info->className,"$DefaultProvider$")==0) defaultProvInfoPtr=info;
               }   
               else if (interOpProvInfoPtr==NULL) {
                  if (strcmp(info->className,"$InterOpProvider$")==0) {
                     if (exFlags & 2) interOpProvInfoPtr=info;
                     else interopFound=1;
                  }   
               }               
               else if (qualiProvInfoPtr==NULL) {
                  if (strcmp(info->className,"$QualifierProvider$")==0) qualiProvInfoPtr=info;
               }
               err = addProviderToHT(info, ((ProviderBase *) br->hdl)->ht);
	       if (err)
		  break;
            }
            info = (ProviderInfo *) calloc(1, sizeof(ProviderInfo));
            info->className = strdup(rv.id);
            info->id= ++id;
            // Set the default provider uid
            info->uid=provuid;
            if (!provSFCB)
               info->user=strdup(provuser);
            break;
         case 2:
            if (strcmp(rv.id, "provider") == 0)
               info->providerName = strdup(cntlGetVal(&rv));
            else if (strcmp(rv.id, "location") == 0)
               info->location = strdup(cntlGetVal(&rv));
            else if (strcmp(rv.id, "parameters") == 0) {
               info->parms = strdup(cntlGetStr(&rv));
               for (i=strlen(info->parms); i>0 && info->parms[i]<=' '; i--) {
                   info->parms[i]=0;
               }
            }
            else if (strcmp(rv.id, "user") == 0) {
               info->user = strdup(cntlGetVal(&rv));
               errno=0;
               passwd=getpwnam(info->user);
               if (passwd) {
                  info->uid=passwd->pw_uid;
               } else {
                  mlogf(M_ERROR,M_SHOW,"--- Couldn't find username %s requested in providerRegister. Errno: %d\n",info->user,errno);
                  err = 1;
                  break;
               }
            }
            else if (strcmp(rv.id, "group") == 0)
               info->group = strdup(cntlGetVal(&rv));
            else if (strcmp(rv.id, "unload") == 0) {
               char *u;
               info->unload = 0;
               while ((u = cntlGetVal(&rv)) != NULL) {
                  if (strcmp(u, "never") == 0) {
                     info->unload =-1;
                  }   
                  else {
                     mlogf(M_ERROR,M_SHOW,"--- invalid unload specification: \n\t%d: %s\n", n, stmt);
                     err = 1;
                  }
               }   
            }   
            else if (strcmp(rv.id, "type") == 0) {
               char *t;
               info->type = 0;
               while ((t = cntlGetVal(&rv)) != NULL) {
                  if (strcmp(t, "instance") == 0)
                     info->type |= INSTANCE_PROVIDER;
                  else if (strcmp(t, "association") == 0)
                     info->type |= ASSOCIATION_PROVIDER;
                  else if (strcmp(t, "method") == 0)
                     info->type |= METHOD_PROVIDER;
                  else if (strcmp(t, "indication") == 0)
                     info->type |= INDICATION_PROVIDER;
                  else if (strcmp(t, "class") == 0)
                     info->type |= CLASS_PROVIDER;
                  else if (strcmp(t, "property") == 0)
                     info->type |= PROPERTY_PROVIDER; 
                  else if (strcmp(t, "qualifier") == 0)
                     info->type |= QUALIFIER_PROVIDER;                     
                  else {
                     mlogf(M_ERROR,M_SHOW,"--- invalid type specification: \n\t%d: %s\n", n, stmt);
                     err = 1;
                  }
               }
            }
            else if (strcmp(rv.id, "namespace") == 0) {
               int max=1,next=0;
               char *t;
               info->ns=(char**)malloc(sizeof(char*)*(max+1));
               while ((t = cntlGetVal(&rv)) != NULL) {
                  if (next==max) {
                     max++;
                     info->ns=(char**)realloc(info->ns,sizeof(char*)*(max+1));
                  }
                  info->ns[next]=strdup(t);
                  info->ns[++next]=NULL;
               }
            }
            else {
               mlogf(M_ERROR,M_SHOW,"--- invalid registration statement: \n\t%d: %s\n", n, stmt);
               err = 1;
            }
            break;
         case 3:
            break;
         }
	 if (err)
	    break;
      }

      if (info) {
	if (err == 0) {
	  err = addProviderToHT(info, ((ProviderBase *) br->hdl)->ht);
        }
	else {
	  freeInfoPtr(info);
	}
      }
   }
   if (in) {
     fclose(in);
   }
   
   if (classProvInfoPtr==NULL) {
      mlogf(M_ERROR,M_SHOW,"--- Class provider definition not found - sfcbd will terminate\n");
      err=1;
   }
   
   if (defaultProvInfoPtr==NULL) 
      mlogf(M_INFO,M_SHOW,"--- Default provider definition not found - no instance repository available\n");

   if (qualiProvInfoPtr==NULL) 
      mlogf(M_INFO,M_SHOW,"--- Qualifier provider definition not found - no qualifier support available\n");
   
   if (interOpProvInfoPtr==NULL) {
      if (exFlags & 2 && interopFound==0)
         mlogf(M_INFO,M_SHOW,"--- InterOp provider definition not found - no InterOp support available\n");
      else if (interopFound)    
         mlogf(M_INFO,M_SHOW,"--- InterOp provider definition found but not started - no InterOp support available\n");
      interOpProvInfoPtr=&forceNotFound;
   }   
   
   if (err) {
      mlogf(M_ERROR,M_SHOW,"--- Broker terminated because of previous error(s)\n");
      exit(5);
   }
   if (stmt) free(stmt);
   return br;
}
Beispiel #2
0
int
setupControl(char *fn)
{
  FILE           *in;
  char            fin[1024],
                 *stmt = NULL;
  int             i,
                  m,
                  n = 0,
      err = 0;
  CntlVals        rv;
  char *configFile;

  if (ct)
    return 0;

  ct = UtilFactory->newHashTable(61, UtilHashTable_charKey |
                                 UtilHashTable_ignoreKeyCase);

  for (i = 0, m = sizeof(init) / sizeof(Control); i < m; i++) {
    ct->ft->put(ct, init[i].id, &init[i]);
  }

  if (fn) {
    if (strlen(fn) >= sizeof(fin))
      mlogf(M_ERROR,M_SHOW, "--- \"%s\" too long\n", fn);
    strncpy(fin,fn,sizeof(fin));
  } 
  else if ((configFile = getenv("SFCB_CONFIG_FILE")) != NULL && configFile[0] != '\0') {
    if (strlen(configFile) >= sizeof(fin))
      mlogf(M_ERROR,M_SHOW, "--- \"%s\" too long\n", configFile);
    strncpy(fin,configFile,sizeof(fin));
  } else {
    strncpy(fin, SFCB_CONFDIR "/sfcb.cfg", sizeof(fin));
  }
  fin[sizeof(fin)-1] = '\0';

  if (fin[0] == '/')
    mlogf(M_INFO, M_SHOW, "--- Using %s\n", fin);
  else
    mlogf(M_INFO, M_SHOW, "--- Using ./%s\n", fin);
  in = fopen(fin, "r");
  if (in == NULL) {
    mlogf(M_ERROR, M_SHOW, "--- %s not found\n", fin);
    return -2;
  }

  while (fgets(fin, 1024, in)) {
    n++;
    if (stmt)
      free(stmt);
    stmt = strdup(fin);
    switch (cntlParseStmt(fin, &rv)) {
    case 0:
    case 1:
      mlogf(M_ERROR, M_SHOW,
            "--- control statement not recognized: \n\t%d: %s\n", n, stmt);
      err = 1;
      break;
    case 2:
      for (i = 0; i < sizeof(init) / sizeof(Control); i++) {
        if (strcmp(rv.id, init[i].id) == 0) {
          if (init[i].type == 3) {
            /*
             * unstripped character string 
             */
            init[i].strValue = strdup(rv.val);
            if (strchr(init[i].strValue, '\n'))
              *(strchr(init[i].strValue, '\n')) = 0;
            init[i].dupped = 1;
          } else {
            init[i].strValue = strdup(cntlGetVal(&rv));
            init[i].dupped = 1;
          }
          goto ok;
        }
      }
      mlogf(M_ERROR, M_SHOW, "--- invalid control statement: \n\t%d: %s\n",
            n, stmt);
      err = 1;
    ok:
      break;
    case 3:
      break;
    }
  }
  if (stmt)
    free(stmt);

  fclose(in);

  if (err) {
    mlogf(M_INFO, M_SHOW,
          "--- Broker terminated because of previous error(s)\n");
    abort();
  }

  return 0;
}