예제 #1
0
static pwr_tStatus configure_parse_attr( ldh_sMenuCall *ip, pwr_tAttrRef *parent, char *str)
{
  int nr;
  unsigned int disable_mask;
  char attr[80];
  pwr_tAttrRef aaref;
  pwr_tStatus sts;

  // Read attribute and mask

  nr = sscanf( str, "%s %d", attr, &disable_mask);
  if ( nr != 2)
    return LDH__COMPSYNTAX;

  // printf( "-- Setting disable mask %d on object '%s'\n", disable_mask, attr);

  sts = ldh_ArefANameToAref( ip->PointedSession, parent, attr, 
			     &aaref);
  if ( ODD(sts)) {
    sts = configure_object( ip, &aaref, disable_mask);
    if ( EVEN(sts)) return sts;
  
    sts = configure_attrmask( ip, &aaref, str);
    if ( EVEN(sts)) return sts;
  }

  return LDH__SUCCESS;
}
예제 #2
0
static pwr_tStatus configure_object( ldh_sMenuCall *ip, pwr_sAttrRef *aref, 
				     unsigned int disable_mask)
{
  pwr_tStatus 	sts;
  pwr_tCid 	cid;
  ldh_sParDef 	*bodydef;
  int 		rows;
  int		i;
  pwr_sAttrRef  aaref, daref;
  pwr_tDisableAttr disable;
  int disableattr_cnt = 0;
  
  sts = ldh_GetAttrRefTid( ip->PointedSession, aref, &cid);
  if ( EVEN(sts)) return sts;

  sts = ldh_GetObjectBodyDef( ip->PointedSession, cid, "RtBody", 1,
				  &bodydef, &rows);
  if (EVEN(sts)) return sts;

  for ( i = 0; i < rows; i++) {
    if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_DISABLEATTR) {
      // Disable or enable dependent on mask
      sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref);
      if ( EVEN(sts)) return sts;

      daref = cdh_ArefToDisableAref( &aaref);

      if ( (1 << disableattr_cnt++) & disable_mask)
	disable = 1;
      else
	disable = 0;

      sts = ldh_WriteAttribute( ip->PointedSession, &daref, (void *)&disable, 
				sizeof(disable));
      if ( EVEN(sts)) return sts;
    }
#if 0
    if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_CLASS) {
      // Examine object attribute
      sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref);
      if ( EVEN(sts)) return sts;

      sts = configure_object( ip, &aaref, disable_mask, disableattr_cnt);
      if ( EVEN(sts)) return sts;
    }
#endif
  }
  free( (char *)bodydef);

  return LDH__SUCCESS;
}
예제 #3
0
파일: unpriv.c 프로젝트: amotzkau/ldmud
int run_test()
{
    int errors;
    string res;

    configure_object(this_object(), OC_EUID, "efun");

    CHECK_PREFIX(geteuid, "lfun");
    CHECK_PREFIX(inh::geteuid, "inh");
    CHECK_PREFIX(efun::geteuid, "efun");
    CHECK_PREFIX(sefun::geteuid, "sefun");

    return errors;
}
예제 #4
0
static pwr_tStatus ConfigureComponent( ldh_sMenuCall *ip) 
{
  pwr_tStatus sts;
  unsigned int disable_mask;
  pwr_sMenuButton   mb;
  pwr_tEnum graph_configuration;
  pwr_sAttrRef aaref;
  char vect[10][80];
  char item[3][80];
  int i;
  int nr;
  int vect_cnt;
  
  sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));

  // Reset previoius disable configuration
  configure_object_reset( ip, &ip->Pointed, &mb);

  // Set disable attributes from argument 0
  if ( mb.MethodArguments[0][0] != '(') {
    // Old syntax, eg '7, CircuitBreaker 4, Contactor 5'
    vect_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *)vect, 
			   sizeof( vect) / sizeof( vect[0]), 
			   sizeof( vect[0]), 0);
  
    for ( i = 0; i < vect_cnt; i++) {
      nr = dcli_parse( vect[i], " 	", "", (char *)item,
		       sizeof( item) / sizeof( item[0]), 
		       sizeof( item[0]), 0);
      if ( nr == 1) {
	
	if ( sscanf( item[0], "%d", &disable_mask) != 1)
	  graph_configuration = 0;

	sts = configure_object( ip, &ip->Pointed, disable_mask);
	if ( EVEN(sts)) return sts;
      }
      else if ( nr == 2) {
	pwr_tAName aname;
	
	if ( sscanf( item[1], "%d", &disable_mask) != 1)
	  disable_mask = 0;

	strncpy( aname, item[0], sizeof(aname));
	
	sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				   &aaref);
	if ( ODD(sts)) {
	  sts = configure_object( ip, &aaref, disable_mask);
	  if ( EVEN(sts)) return sts;
	}
      }
    }
  }
  else {
    // New syntax, eg '(7 (CircuitBreaker 4, Contactor 5))'
    char str1[256];
    char *s;

    strncpy( str1, &mb.MethodArguments[0][1], sizeof(str1));
    s = strrchr( str1, ')');
    if ( !s)
      return LDH__COMPSYNTAX;

    *s = 0;
    
    dcli_trim( str1, str1);
    nr = sscanf( str1, "%d", &disable_mask);
    if ( nr != 1)
      return LDH__COMPSYNTAX;

    sts = configure_object( ip, &ip->Pointed, disable_mask);
    if ( EVEN(sts)) return sts;

    sts = configure_attrmask( ip, &ip->Pointed, str1);
    if ( EVEN(sts)) return sts;
  }

  // Set GraphConfiguration from argument 1
  vect_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *)vect, 
		   sizeof( vect) / sizeof( vect[0]), 
		   sizeof( vect[0]), 0);
  
  for ( i = 0; i < vect_cnt; i++) {
    nr = dcli_parse( vect[i], " 	", "", (char *)item,
		   sizeof( item) / sizeof( item[0]), 
		   sizeof( item[0]), 0);
    if ( nr == 1) {

      if ( sscanf( item[0], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, "GraphConfiguration", 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
    else if ( nr == 2) {
      pwr_tAName aname;

      if ( sscanf( item[1], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      strncpy( aname, item[0], sizeof(aname));
      strncat( aname, ".GraphConfiguration", sizeof(aname));

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
  }
  return 1;
}
예제 #5
0
static pwr_tStatus ConfigureComponent( ldh_sMenuCall *ip) 
{
  pwr_tStatus sts;
  unsigned int disable_mask;
  pwr_sMenuButton   mb;
  pwr_tEnum graph_configuration;
  pwr_sAttrRef aaref;
  char vect[10][80];
  char item[3][80];
  int i;
  int nr;
  int vect_cnt;
  
  sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));

  // Reset previoius disable configuration
  configure_object_reset( ip, &ip->Pointed, &mb);

  // Set disable attributes from argument 0
  vect_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *)vect, 
		   sizeof( vect) / sizeof( vect[0]), 
		   sizeof( vect[0]), 0);
  
  for ( i = 0; i < vect_cnt; i++) {
    nr = dcli_parse( vect[i], " 	", "", (char *)item,
		   sizeof( item) / sizeof( item[0]), 
		   sizeof( item[0]), 0);
    if ( nr == 1) {

      if ( sscanf( item[0], "%d", &disable_mask) != 1)
	graph_configuration = 0;

      sts = configure_object( ip, &ip->Pointed, disable_mask);
      if ( EVEN(sts)) return sts;
    }
    else if ( nr == 2) {
      pwr_tAName aname;

      if ( sscanf( item[1], "%d", &disable_mask) != 1)
	disable_mask = 0;

      strcpy( aname, item[0]);

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				 &aaref);
      if ( ODD(sts)) {
	sts = configure_object( ip, &aaref, disable_mask);
	if ( EVEN(sts)) return sts;
      }
    }
  }

  // Set GraphConfiguration from argument 1
  vect_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *)vect, 
		   sizeof( vect) / sizeof( vect[0]), 
		   sizeof( vect[0]), 0);
  
  for ( i = 0; i < vect_cnt; i++) {
    nr = dcli_parse( vect[i], " 	", "", (char *)item,
		   sizeof( item) / sizeof( item[0]), 
		   sizeof( item[0]), 0);
    if ( nr == 1) {

      if ( sscanf( item[0], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, "GraphConfiguration", 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
    else if ( nr == 2) {
      pwr_tAName aname;

      if ( sscanf( item[1], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      strcpy( aname, item[0]);
      strcat( aname, ".GraphConfiguration");

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
  }
  return 1;
}