示例#1
0
char *RemoteLink( char *config, bool server )
{
    char        *msg;
    char        *end;

    server=server;
    end = ValidName( config );
    strcpy( NameBuff+1, PREFIX );
    if( end == NULL ) {
        return( TRP_ERR_invalid_server_name_format_is );
    } else {
        if( end == config ) {
            strcpy( NameBuff+1 + PREFIX_LEN, DefLinkName );
        } else {
            memcpy( NameBuff+1 + PREFIX_LEN, config, end-config );
            NameBuff[ end-config+1+PREFIX_LEN ] = '\0';
        }
    }
    msg = OpenRequest();
    NameEnd = NameBuff + strlen( NameBuff );
    if( msg != NULL ) return( msg );
    if( NameBuff[0] != BIND_ACK ) {
#ifdef SERVER
        return( TRP_ERR_server_name_already_in_use );
#else
        return( TRP_ERR_server_not_found );
#endif
    } else {
        DoOpen( &ConnHdl, CONN_SUFF );
    }
    return( NULL );
}
示例#2
0
int DeleteNFSService(int argc, char **argv)
{
  int stat;
  struct mqelem *elem = NULL;
  char *args[10];

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  args[0] = canonicalize_hostname(strdup(argv[1]));
  args[1] = strdup(DEFAULT_DIR);
  if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
    return DM_NORMAL;

  switch ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, &elem)))
    {
    case MR_NO_MATCH:
      Put_message("This filsystem does not exist!");
      return DM_NORMAL;
    case MR_SUCCESS:
      break;
    default:
      com_err(program_name, stat, " in DeleteNFSService");
      return DM_NORMAL;
    }
  free(args[0]);
  free(args[1]);		/* stop memory leaks, in your neighborhood. */

  QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
	    "Delete the Physical Filesystem on Directory");

  FreeQueue(elem);
  return DM_NORMAL;
}
示例#3
0
int GetMemberInfo(char *action, char **ret_argv)
{
  char temp_buf[BUFSIZ];

  ret_argv[LM_LIST] = strdup(current_list);

  ret_argv[LM_TYPE] = strdup("user");
  if (GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]) ==
      SUB_ERROR)
    return SUB_ERROR;

  sprintf(temp_buf, "Name of %s to %s", ret_argv[LM_TYPE], action);
  ret_argv[LM_MEMBER] = strdup(user);
  if (GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]) == SUB_ERROR)
    return SUB_ERROR;
  ret_argv[LM_END] = NULL;		/* NULL terminate this list. */

  if (strcasecmp(ret_argv[LM_TYPE], "string") &&
      !ValidName(ret_argv[LM_MEMBER]))
    {
      FreeInfo(ret_argv);
      return SUB_ERROR;
    }
  return SUB_NORMAL;
}
示例#4
0
int UpdateNFSService(int argc, char **argv)
{
  int stat;
  struct mqelem *elem = NULL;
  char *args[10];

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  args[0] = canonicalize_hostname(strdup(argv[1]));
  args[1] = strdup(DEFAULT_DIR);
  if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
    return DM_NORMAL;

  if ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, &elem)))
    {
      com_err(program_name, stat, " in UpdateNFSService.");
      return DM_NORMAL;
    }
  free(args[0]);
  free(args[1]);		/* stop memory leaks. */

  elem = QueueTop(elem);
  QueryLoop(elem, UpdatePrint, RealUpdateNFSService, "Update NFS Service for");

  FreeQueue(elem);
  return DM_NORMAL;
}
示例#5
0
int ShowNFSService(int argc, char **argv)
{
  int stat;
  struct mqelem *elem = NULL;
  char *args[10];

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  args[0] = canonicalize_hostname(strdup(argv[1]));
  args[1] = strdup(DEFAULT_DIR);
  if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
    return DM_NORMAL;

  if ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, &elem)))
    com_err(program_name, stat, " in ShowNFSServices.");
  free(args[0]);
  free(args[1]);		/* prevents memory leaks. */

  elem = QueueTop(elem);
  Loop(elem, (void (*)(char **)) PrintNFSInfo);

  FreeQueue(elem);
  return DM_NORMAL;
}
示例#6
0
文件: printer.c 项目: jdreed/moira
int AddPrn(int argc, char **argv)
{
  char *info[MAX_ARGS_SIZE], **args;
  int stat;

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  if (!(stat = do_mr_query("get_printer", 1, argv + 1, NULL, NULL)) ||
      !(stat = do_mr_query("get_printer_by_duplexname", 1, argv + 1,
			   NULL, NULL)))
    {
      Put_message ("A Printer by that name already exists.");
      return DM_NORMAL;
    }
  else if (stat != MR_NO_MATCH)
    {
      com_err(program_name, stat, " in AddPrn");
      return DM_NORMAL;
    }

  args = AskPrnInfo(SetDefaults(info, argv[1]), FALSE);
  if (!args)
    {
      Put_message("Aborted.");
      return DM_NORMAL;
    }

  if ((stat = do_mr_query("add_printer", CountArgs(args), args, NULL, NULL)))
    com_err(program_name, stat, " in AddPrn");

  if (stat == MR_SUCCESS && strcasecmp(info[PRN_HOSTNAME], "[NONE]"))
    {
      char *hwargv[2], *hwaddr, *s, *d;

      hwaddr = strdup("");
      if (GetValueFromUser("Hardware ethernet address", &hwaddr) == SUB_ERROR)
	return DM_NORMAL;

      s = d = hwaddr;
      do
	{
	  if (*s != ':')
	    *d++ = *s;
	}
      while (*s++);

      hwargv[0] = info[PRN_HOSTNAME];
      hwargv[1] = hwaddr;

      stat = do_mr_query("add_host_hwaddr", 2, hwargv, NULL, NULL);
      if (stat != MR_SUCCESS)
	com_err(program_name, stat, " in add_host_hwaddr");
    }
  
  FreeInfo(info);
  return DM_NORMAL;
}
示例#7
0
int AddNFSService(int argc, char **argv)
{
  char **add_args, *args[10];
  char *info[MAX_ARGS_SIZE];
  int stat;

  args[0] = canonicalize_hostname(strdup(argv[1]));
  args[1] = strdup(DEFAULT_DIR);
  if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR)
    return DM_NORMAL;

  if (!ValidName(args[0]) || !ValidName(args[1]))
    return DM_NORMAL;

  if (!(stat = do_mr_query("get_nfsphys", 2, args, NULL, NULL)))
    stat = MR_EXISTS;
  if (stat != MR_NO_MATCH)
    {
      com_err(program_name, stat, " in get_nfsphys.");
      return DM_NORMAL;
    }

  info[NFS_NAME]   = strdup(args[0]);
  info[NFS_DIR]    = args[1];	/* already saved. */
  info[NFS_DEVICE] = strdup(DEFAULT_DEVICE);
  info[NFS_STATUS] = strdup(DEFAULT_STATUS);
  info[NFS_ALLOC]  = strdup(DEFAULT_ALLOC);
  info[NFS_SIZE]   = strdup(DEFAULT_SIZE);
  info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
  info[NFS_END] = NULL;

  if (!(add_args = AskNFSInfo(info)))
    {
      Put_message("Aborted.");
      return DM_NORMAL;
    }

  if ((stat = do_mr_query("add_nfsphys", CountArgs(add_args), add_args,
			  NULL, NULL)))
    com_err(program_name, stat, " in AdsNFSService");

  FreeInfo(info);
  free(args[0]);
  return DM_NORMAL;
}
示例#8
0
int InterRemoveItemFromLists(int argc, char **argv)
{
  int status;
  char *type, *name, *args[10], buf[BUFSIZ];
  struct mqelem *top, *elem;

  type = strdup("USER");
  if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
    return DM_NORMAL;

  sprintf(buf, "Name of %s", type);
  name = strdup(user);
  if (GetValueFromUser(buf, &name) == SUB_ERROR)
    return DM_NORMAL;

  if (!ValidName(name))
    return DM_NORMAL;

  top = elem = GetListInfo(GLOM, type, name);

  while (elem)
    {
      char line[BUFSIZ];
      char **info = elem->q_data;
      sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type,
	      name, info[GLOM_NAME]);
      switch (YesNoQuitQuestion(line, FALSE))
	{
	case TRUE:
	  Put_message("deleting...");
	  args[DM_LIST] = info[GLOM_NAME];
	  args[DM_TYPE] = type;
	  args[DM_MEMBER] = name;
	  if (!strcmp("MACHINE", type))
	      args[DM_MEMBER] = canonicalize_hostname(strdup(name));
	  if ((status = do_mr_query("delete_member_from_list", 3, args,
				    NULL, NULL)))
	    {
	      /* should probabally check to delete list. */
	      com_err(program_name, status, " in delete_member");
	    }
	  break;
	case FALSE:
	  break;
	default:
	  Put_message("Aborting...");
	  FreeQueue(top);
	  return DM_NORMAL;
	}
      elem = elem->q_forw;
    }
  FreeQueue(top);
  return DM_NORMAL;
}
示例#9
0
int CreateFSAlias(int argc, char **argv)
{
  int stat;
  struct mqelem *elem, *top;
  char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info;

  elem = NULL;

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  args[ALIAS_NAME] = strdup(argv[1]);
  args[ALIAS_TYPE] = strdup(FS_ALIAS_TYPE);
  args[ALIAS_TRANS] = strdup("*");

  /*
   * Check to see if this alias already exists in the database, if so then
   * print out values, free memory used and then exit.
   */

  if (!(stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem)))
    {
      top = elem = QueueTop(elem);
      while (elem)
	{
	  info = elem->q_data;
	  sprintf(buf, "The alias: %s currently describes the filesystem %s",
		  info[ALIAS_NAME], info[ALIAS_TRANS]);
	  Put_message(buf);
	  elem = elem->q_forw;
	}
      FreeQueue(top);
      return DM_NORMAL;
    }
  else if (stat != MR_NO_MATCH)
    {
      com_err(program_name, stat, " in CreateFSAlias.");
      return DM_NORMAL;
    }

  args[ALIAS_TRANS] = strdup("");
  args[ALIAS_END] = NULL;
  if (GetValueFromUser("Which filesystem will this alias point to?",
		       &args[ALIAS_TRANS]) == SUB_ERROR)
    return DM_NORMAL;

  if ((stat = do_mr_query("add_alias", 3, args, NULL, NULL)))
    com_err(program_name, stat, " in CreateFSAlias.");

  FreeInfo(args);
  return DM_NORMAL;
}
示例#10
0
文件: holder.cpp 项目: darkk/porto
TError TContainerHolder::Create(TScopedLock &holder_lock, const std::string &name, const TCred &cred, std::shared_ptr<TContainer> &container) {
    TError error;

    error = ValidName(name);
    if (error)
        return error;

    if (Containers.find(name) != Containers.end())
        return TError(EError::ContainerAlreadyExists, "container " + name + " already exists");

    if (Containers.size() + 1 > config().container().max_total())
        return TError(EError::ResourceNotAvailable, "number of created containers exceeds limit");

    auto parent = GetParent(name);
    if (!parent && name != ROOT_CONTAINER)
        return TError(EError::InvalidValue, "invalid parent container");

    if (parent && parent->GetLevel() == CONTAINER_LEVEL_MAX)
        return TError(EError::InvalidValue, "You shall not go deeper!");

    if (parent && !parent->IsRoot() && !parent->IsPortoRoot()) {
        error = parent->CheckPermission(cred);
        if (error)
            return error;
    }

    int id;
    error = IdMap.Get(id);
    if (error)
        return error;

    auto c = std::make_shared<TContainer>(shared_from_this(), Storage, name, parent, id);
    error = c->Create(cred);
    if (error)
        return error;

    Containers[name] = c;
    Statistics->Created++;

    if (parent)
        parent->AddChild(c);

    container = c;

    return TError::Success();
}
示例#11
0
int DeleteUserByUid(int argc, char **argv)
{
  int status;
  struct mqelem *elem = NULL;
  char **info;

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo,
			    &elem)))
    com_err(program_name, status, " in get_user_account_by_uid");

  info = elem->q_data;
  argv[1] = info[U_NAME];

  DeleteUser(argc, argv);
  return DM_NORMAL;
}
示例#12
0
int ListmaintMemberMenuEntry(Menu *m, int argc, char **argv)
{
  char temp_buf[BUFSIZ];
  char *list_name = argv[1];
  int stat;

  if (!ValidName(list_name))
    return DM_QUIT;

  if (*argv[0] == 'a')
    {	/* add_list */
      if (AddList(argc, argv) == SUB_ERROR)
	return DM_QUIT;
      sprintf(temp_buf, "List '%s' created. Do you want to %s", list_name,
	      "change its membership (y/n)? ");
      if (YesNoQuestion(temp_buf, TRUE) != TRUE)
	return DM_QUIT;
    }
  else
    /* All we want to know is if it exists. */
    switch ((stat = do_mr_query("count_members_of_list", 1, argv + 1,
				NULL, NULL)))
      {
      case MR_SUCCESS:
	break;
      case MR_LIST:
	Put_message("This list does not exist.");
	return DM_QUIT;
      case MR_PERM:
	Put_message("You are not allowed to view this list.");
	break;
      default:
	com_err(program_name, stat, " in get_list_info");
	return DM_QUIT;
      }

  sprintf(temp_buf, "Change/Display membership of '%s'", list_name);
  m->m_title = strdup(temp_buf);
  strcpy(current_list, list_name);
  return DM_NORMAL;
}
示例#13
0
int DeleteUser(int argc, char **argv)
{
  int status;
  char buf[BUFSIZ];
  char *name = argv[1];	/* name of the user we are deleting. */
#ifndef ATHENA
  struct mqelem *local, *member_of = NULL;
#endif

  if (!ValidName(name))
    return DM_NORMAL;

  if (!Confirm("Are you sure that you want to delete this user?"))
    return DM_NORMAL;

  status = do_mr_query("delete_user", 1, &name, NULL, NULL);
  if (status != MR_IN_USE && status != 0)
    {
      com_err(program_name, status, ": user not deleted");
      return DM_NORMAL;
    }
  if (status == 0)
    {
      sprintf(buf, "User %s deleted.", name);
      Put_message(buf);
#ifdef ATHENA
      /* delete this return if the policy decision below is reversed */
      return DM_NORMAL;
#endif
    }
#ifdef ATHENA
  /* Design decision not to allow registered users to be deleted.
   */
  Put_message("Sorry, registered users cannot be deleted from the database.");
  Put_message("Deactivate the user now, and the system manager will expunge later.");
#else
  else if (status == MR_IN_USE)
示例#14
0
int AddFS(int argc, char **argv)
{
  char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ];
  int stat;
  extern Menu nfsphys_menu;

  if (!ValidName(argv[1]))
    return DM_NORMAL;

  if (!(stat = do_mr_query("get_filesys_by_label", 1, argv + 1,
			      NULL, NULL)))
    {
      Put_message ("A Filesystem by that name already exists.");
      return DM_NORMAL;
    }
  else if (stat != MR_NO_MATCH)
    {
      com_err(program_name, stat, " in AddFS");
      return DM_NORMAL;
    }

  if (!(args = AskFSInfo(SetDefaults(info, argv[1]), FALSE)))
    {
      Put_message("Aborted.");
      return DM_NORMAL;
    }

  stat = do_mr_query("add_filesys", CountArgs(args), args, NULL, NULL);
  switch (stat)
    {
    case MR_NFS:
      Put_message("That NFS filesystem is not exported.");
      if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE)
	{
	  Do_menu(&nfsphys_menu, 0, NULL);
	  if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE)
	      == TRUE) {
	    if ((stat = do_mr_query("add_filesys", CountArgs(args), args,
				    NULL, NULL)))
	      com_err(program_name, stat, " in AddFS");
	    else
	      Put_message("Created.");
	  }
	}
      break;
    case MR_SUCCESS:
      break;
    default:
      com_err(program_name, stat, " in AddFS");
    }

  if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR"))
    {
      static char *val[] = {"def_quota", NULL};
      static char *def_quota = NULL;
      char *argv[Q_QUOTA + 1];
      struct mqelem *top = NULL;

      if (!def_quota)
	{
	  stat = do_mr_query("get_value", CountArgs(val), val,
			     StoreInfo, &top);
	  if (stat != MR_SUCCESS)
	    com_err(program_name, stat, " getting default quota");
	  else
	    {
	      top = QueueTop(top);
	      def_quota = strdup(((char **)top->q_data)[0]);
	      FreeQueue(top);
	    }
	}
      if (def_quota)
	{
	  sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)",
		  info[FS_NAME], def_quota, info[FS_NAME]);
	  if (YesNoQuestion(buf, 1) == TRUE)
	    {
	      argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME];
	      if (!strcmp(info[FS_TYPE], "NFS"))
		argv[Q_TYPE] = "USER";
	      else
		argv[Q_TYPE] = "ANY";
	      argv[Q_QUOTA] = def_quota;
	      if ((stat = do_mr_query("add_quota", Q_QUOTA + 1, argv, NULL,
				      NULL)))
		com_err(program_name, stat, " while adding quota");
	    }
	}
    }
  else if (stat == MR_SUCCESS)
    {
      if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1) == TRUE)
	{
	  parsed_argc = 1;
	  parsed_argv[0] = info[FS_NAME];
	  AddQuota(parsed_argc, parsed_argv);
	}
    }

  FreeInfo(info);
  return DM_NORMAL;
}
示例#15
0
int AddList(int argc, char **argv)
{
  static char *info[MAX_ARGS_SIZE], **add_args;
  int status, ret_code = SUB_NORMAL;
  struct mqelem *elem = NULL;

  if (!ValidName(argv[1]))
    return DM_NORMAL;
  status = do_mr_query("get_list_info", 1, argv + 1, NULL, NULL);
  if (status != MR_NO_MATCH)
    {
      if (status == MR_SUCCESS)
	Put_message("This list already exists.");
      else
	com_err(program_name, status, " in AddList.");
      return SUB_ERROR;
    }

  if (status = mr_access("add_list", L_MODTIME, SetDefaults(info, argv[1]))) 
    {
      com_err(program_name, status, " in AddList.");
      return SUB_ERROR;
    }

  /*
   * If the listname is less than 8 characters, make sure it doesn't
   * collide with a username.
   */
  if ((strlen(argv[1]) <= 8) &&
      do_mr_query("get_user_account_by_login", 1, argv + 1,
		  StoreInfo, &elem) != MR_NO_MATCH)
    {
      char buf[256];

      sprintf(buf, "\nA user by the name `%s' already exists in the database.",
	      argv[1]);
      Put_message(buf);
      Loop(QueueTop(elem), FreeInfo);
      FreeQueue(elem);
      if (YesNoQuestion("Create a list with the same name", FALSE) != TRUE)
	return SUB_ERROR;
    }

  if (!(add_args = AskListInfo(SetDefaults(info, argv[1]), FALSE)))
    {
      Put_message("Aborted.");
      return SUB_ERROR;
    }

  if ((status = do_mr_query("add_list", CountArgs(add_args), add_args,
			    NULL, NULL)) != MR_SUCCESS)
    {
      com_err(program_name, status, " in AddList.");
      Put_message("List Not Created.");
      ret_code = SUB_ERROR;
    }

  if (atoi(add_args[L_MAILMAN]))
    {
      char mailman_address[256], buf[1024];

      status = do_mr_query("get_list_info", 1, add_args, StoreInfo, &elem);
      if (status)
	  com_err(program_name, status, "while retrieving list information.");
      else
	{
	  strcpy(mailman_address, add_args[0]);
	  strcat(mailman_address, "@");
	  strcat(mailman_address, ((char **)elem->q_data)[L_MAILMAN_SERVER]);
	  sprintf(buf, "Add STRING %s to LIST %s", mailman_address,
		  add_args[0]);
	  if (YesNoQuestion(buf, TRUE) == TRUE)
	    {
	      char *args[3];
	      args[0] = add_args[0];
	      args[1] = "STRING";
	      args[2] = mailman_address;
	      
	      status = do_mr_query("add_member_to_list", CountArgs(args), args,
				   NULL, NULL);
	      if (status)
		com_err(program_name, status, "while adding member to list.");
	    }
	}
    }

  FreeInfo(info);
  return ret_code;
}
示例#16
0
// virtual
CXMLHandler * ReportDefinitionHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  const char * Key;
  const char * Name;
  const char * Separator;
  const char * Precision;
  CTaskEnum::Task type;

  switch (mCurrentElement.first)
    {
      case ReportDefinition:
        Key = mpParser->getAttributeValue("key", papszAttrs);
        Name = mpParser->getAttributeValue("name", papszAttrs);
        type = CTaskEnum::TaskXML.toEnum(mpParser->getAttributeValue("taskType", papszAttrs), CTaskEnum::Task::UnsetTask);

        Separator = mpParser->getAttributeValue("separator", papszAttrs, "\t");
        Precision = mpParser->getAttributeValue("precision", papszAttrs, "6");

        // create a new report
        mpData->pReport = new CReportDefinition();
        mpData->pReport->setTaskType(type);
        mpData->pReport->setSeparator(Separator);
        mpData->pReport->setPrecision(strToUnsignedInt(Precision));

        {
          // We need to make sure that the name is unique.
          std::string ValidName(Name);
          size_t Index = 1;

          while (mpData->pReportList->getIndex(ValidName) != C_INVALID_INDEX)
            {
              std::ostringstream ValidNameStream;
              ValidNameStream << Name << " " << Index++;
              ValidName = ValidNameStream.str();
            }

          mpData->pReport->setObjectName(ValidName);
        }

        /* We have a new report and add it to the list */
        mpData->pReportList->add(mpData->pReport, true);
        addFix(Key, mpData->pReport);
        break;

      case Comment:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case Header:
      case Body:
      case Footer:
        mpData->pReport->setIsTable(false);
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case Table:
        mpData->pReport->setIsTable(true);
        pHandlerToCall = getHandler(mCurrentElement.second);

        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}