Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
int ListByAdministrator(int argc, char **argv)
{
  char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
  struct mqelem *top;

  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;

  switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE))
    {
    case TRUE:
      sprintf(temp_buf, "R%s", type);	/* "USER" to "RUSER" etc. */
      free(type);
      type = strdup(temp_buf);
      break;
    case FALSE:
      break;
    default:
      return DM_NORMAL;
    }

  top = GetListInfo(ACE_USE, type, name);
  Loop(top, PrintListAce);

  FreeQueue(top);
  return DM_NORMAL;
}
Exemplo n.º 4
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;
}
Exemplo n.º 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;
}
Exemplo n.º 6
0
int UserBySponsor(int argc, char **argv)
{
  char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
  struct mqelem *top;

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

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

  switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE))
    {
    case TRUE:
      sprintf(temp_buf, "R%s", type);     /* "USER to "RUSER", etc. */
      free(type);
      type = strdup(temp_buf);
      break;
    case FALSE:
      break;
    default:
      return DM_NORMAL;
    }

  top = GetUserBySponsor(type, name);
  Loop(top, PrintLogin);

  FreeQueue(top);
  return DM_NORMAL;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
static char *GetLoginName(void)
{
  char *name;

  name = strdup("");
  if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
    return NULL;
  Put_message("KERBEROS code not added, did not reserve name with kerberos.");
  return name;
}
Exemplo n.º 9
0
int ListByMember(int argc, char **argv)
{
  char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info;
  Bool maillist, group, neither;
  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;

  switch (YesNoQuestion("Do you want a recursive search (y/n)", TRUE))
    {
    case TRUE:
      sprintf(temp_buf, "R%s", type);	/* "USER" to "RUSER" etc. */
      free(type);
      type = strdup(temp_buf);
      break;
    case FALSE:
      break;
    default:
      return DM_NORMAL;
    }

  if ((maillist = YesNoQuestion("Show Lists that are Maillists (y/n) ?",
				TRUE)) == -1)
    return DM_NORMAL;
  if ((group = YesNoQuestion("Show Lists that are Groups (y/n) ?",
			     TRUE)) == -1)
    return DM_NORMAL;

  if ((neither = YesNoQuestion("Show Lists that are neither Maillists nor Groups (y/n) ?",
			       TRUE)) == -1)
    return DM_NORMAL;

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

  while (elem)
    {
      info = elem->q_data;
      if ((maillist == TRUE && !strcmp(info[GLOM_MAILLIST], "1")) ||
	  (group == TRUE && !strcmp(info[GLOM_GROUP], "1")))
	Put_message(info[GLOM_NAME]);
      if (neither == TRUE && !strcmp(info[GLOM_MAILLIST], "0") &&
	   !strcmp(info[GLOM_GROUP], "0"))
	Put_message(info[GLOM_NAME]);
      elem = elem->q_forw;
    }
  FreeQueue(top);
  return DM_NORMAL;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
int AddFSToGroup(int argc, char **argv)
{
  int stat, count;
  struct mqelem *elem = NULL;
  char buf[BUFSIZ], *args[5], *bufp;

  if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo,
			  &elem)))
    {
      if (stat != MR_NO_MATCH)
	com_err(program_name, stat, " in AddFSToGroup");
    }
  if (elem == NULL)
    {
      args[0] = argv[1];
      args[1] = argv[2];
      args[2] = "M";
      stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL);
      if (stat)
	com_err(program_name, stat, " in AddFSToGroup");
      return DM_NORMAL;
    }
  elem = QueueTop(elem);
  fsgCount = 1;
  Loop(elem, PrintFSGMembers);
  sprintf(buf, "%d", QueueCount(elem));
  bufp = strdup(buf);
  if (GetValueFromUser("Enter number of filesystem it should follow "
		       "(0 to make it first):", &bufp) == SUB_ERROR)
    return DM_NORMAL;
  count = atoi(bufp);
  free(bufp);
  args[2] = SortAfter(elem, count);

  FreeQueue(QueueTop(elem));
  args[0] = argv[1];
  args[1] = argv[2];
  stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL);
  if (stat == MR_EXISTS)
    {
      Put_message("That filesystem is already a member of the group.");
      Put_message("Use the order command if you want to change the "
		  "sorting order.");
    }
  else if (stat)
    com_err(program_name, stat, " in AddFSToGroup");
  return DM_NORMAL;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
int TagMember(int argc, char **argv)
{
  char *args[10];
  int status;

  if (GetMemberInfo("tag", args) == SUB_ERROR)
    return DM_NORMAL;

  args[LM_TAG] = strdup("");
  if (GetValueFromUser("Tag" , &args[LM_TAG]) == SUB_ERROR)
    {
      Put_message("Aborted.");
      return DM_NORMAL;
    }
  args[LM_TAG_END] = NULL;		/* NULL terminate this list. */

  if ((status = do_mr_query("tag_member_of_list", CountArgs(args),
			    args, NULL, NULL)))
    com_err(program_name, status, " in TagMember");

  FreeInfo(args);
  return DM_NORMAL;
}
Exemplo n.º 15
0
int ChangeFSGroupOrder(int argc, char **argv)
{
  int stat, src, dst, i;
  struct mqelem *elem = NULL, *top, *tmpelem;
  char buf[BUFSIZ], *bufp, *args[3];

  if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo,
			  &elem)))
    {
      if (stat == MR_NO_MATCH)
	{
	  sprintf(buf,
		  "Ether %s is not a filesystem group or it has no members",
		  argv[1]);
	  Put_message(buf);
	}
      else
	com_err(program_name, stat, " in ChangeFSGroupOrder");
      return DM_NORMAL;
    }
  top = QueueTop(elem);
  fsgCount = 1;
  Loop(top, PrintFSGMembers);
  while (1)
    {
      bufp = strdup("1");
      if (GetValueFromUser("Enter number of the filesystem to move:",
			   &bufp) == SUB_ERROR)
	return DM_NORMAL;
      src = atoi(bufp);
      free(bufp);
      if (src < 0)
	{
	  Put_message("You must enter a positive number (or 0 to abort).");
	  continue;
	}
      else if (src == 0)
	{
	  Put_message("Aborted.");
	  return DM_NORMAL;
	}
      for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw)
	;
      if (i > 0)
	{
	  Put_message("You entered a number that is too high");
	  continue;
	}
      break;
    }
  while (1)
    {
      bufp = strdup("0");
      if (GetValueFromUser("Enter number of filesystem it should follow "
			   "(0 to make it first):", &bufp) == SUB_ERROR)
	return DM_NORMAL;
      dst = atoi(bufp);
      free(bufp);
      if (src == dst || src == dst + 1)
	{
	  Put_message("That has no effect on the sorting order!");
	  return DM_NORMAL;
	}
      if (dst < 0)
	{
	  Put_message("You must enter a non-negative number.");
	  continue;
	}
      for (tmpelem = top, i = dst; i-- > 1 && tmpelem->q_forw;
	   tmpelem = tmpelem->q_forw)
	;
      if (i > 0)
	{
	  Put_message("You entered a number that is too high");
	  continue;
	}
      break;
    }
  args[2] = SortAfter(top, dst);
  args[0] = argv[1];
  args[1] = ((char **)elem->q_data)[0];
  if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args,
			  NULL, NULL)))
    {
      com_err(program_name, stat, " in ChangeFSGroupOrder");
      return DM_NORMAL;
    }
  if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args,
			     NULL, NULL)))
    com_err(program_name, stat, " in ChangeFSGroupOrder");
  return DM_NORMAL;
}
Exemplo n.º 16
0
int RegisterUser(int argc, char **argv)
{
  char *args[MAX_ARGS_SIZE];
  char *login, *potype = NULL;
  char temp_buf[BUFSIZ];
  int status, i;

  for (i = 0; i < MAX_ARGS_SIZE; i++)
    args[i] = NULL;

  Put_message("This function has NO kerberos support, so strange things");
  Put_message("may happen if you use it to register a user.");

  switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE))
    {
    case TRUE:
      Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
      args[0] = strdup(temp_buf);
      break;
    case FALSE:
      if (!(args[0] = GetUidNumberFromName()))
	return DM_NORMAL;
      break;
    default:
      return DM_NORMAL;
    }

  sprintf(temp_buf, "u%s", args[0]);
  login = strdup(temp_buf);
  if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR)
    {
      args[1] = login;
      FreeInfo(args);	   /* This work because the NULL temination is ok. */
      return DM_NORMAL;
    }
  Put_message("KERBEROS code not added, did not reserve name with kerberos.");
  args[1] = login;
  
  sprintf(temp_buf, "EXCHANGE");
  potype = strdup(temp_buf);
  if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR)
    {
      args[2] = potype;
      FreeInfo(args);
      return DM_NORMAL;
    }
  if (strcmp(potype, "POP") && strcmp(potype, "IMAP") && strcmp(potype, "EXCHANGE"))
    {
      sprintf(temp_buf, "Unknown P.O. Box type.");
      Put_message(temp_buf);
      FreeInfo(args);
      return DM_NORMAL;
    }
  args[2] = potype;
  args[3] = NULL;

  switch ((status = do_mr_query("register_user", CountArgs(args),
				args, NULL, NULL)))
    {
    case MR_SUCCESS:
      sprintf(temp_buf, "User %s successfully registered.", login);
      Put_message(temp_buf);
      SetUserPassword(login);
      break;
    case MR_IN_USE:
      GiveBackLogin(login);
      sprintf(temp_buf, "The username %s is already in use.", login);
      Put_message(temp_buf);
      break;
    default:
      com_err(program_name, status, " in register_user");
      break;
    }
  FreeInfo(args);
  return DM_NORMAL;
}