sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
info[FS_OWNER], info[FS_OWNERS]);
Put_message(print_buf);
- sprintf(print_buf, "Auto Create %-34s Locker Type: %s",info[FS_CREATE],
+ sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
+ atoi(info[FS_CREATE]) ? "ON" : "OFF",
info[FS_L_TYPE]);
Put_message(print_buf);
- sprintf(print_buf, "Last Modified at %s, by %s with %s",
- info[FS_MODTIME], info[FS_MODBY], info[FS_MODWITH]);
+ sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
+ info[FS_MODWITH]);
Put_message(print_buf);
return(info[FS_NAME]);
}
GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
- GetValueFromUser("Automatically create this filsystem (0/1)",
+ GetYesNoValueFromUser("Automatically create this filsystem",
&info[FS_CREATE]);
GetValueFromUser("Filesystem's lockertype", &info[FS_L_TYPE]);
Put_message("");
sprintf(buf, "Machine: %-30s Type: %s", info[M_NAME], info[M_TYPE]);
Put_message(buf);
- sprintf(buf, "Last Modified at %s, by %s with %s",info[M_MODTIME],
- info[M_MODBY], info[M_MODWITH]);
+ sprintf(buf, MOD_FORMAT, info[M_MODBY], info[M_MODTIME], info[M_MODWITH]);
Put_message(buf);
return(info[M_NAME]);
}
Put_message(buf);
sprintf(buf, "Location: %s", info[C_LOCATION]);
Put_message(buf);
- sprintf(buf, "Last Modified at %s, by %s with %s",info[C_MODTIME],
- info[C_MODBY], info[C_MODWITH]);
+ sprintf(buf, MOD_FORMAT, info[C_MODBY], info[C_MODTIME], info[C_MODWITH]);
Put_message(buf);
return(info[C_NAME]);
}
#include "globals.h"
#include "infodefs.h"
-static int RealDeleteUser();
-
/* Function Name: CheckListForDeletion
* Description: Check one of the lists in which we just removed a member.
* if the list is empty then it will delete it.
Bool verbose;
{
struct qelem *elem = NULL;
- int status, ans;
+ int status;
char *args[2], buf[BUFSIZ], **info;
if ( (status = sms_query("count_members_of_list", 1, &name, StoreInfo,
if (info[0] == 0) {
if (verbose) {
sprintf(buf, "Delete the empty list %s? ", name);
- ans = YesNoQuestion(buf, TRUE);
- if (ans != TRUE) {
+ if (YesNoQuestion(buf, FALSE) != TRUE) {
Put_message("Aborting Deletion!");
FreeQueue(elem);
return;
FreeQueue(elem);
}
-/* Function Name: CheckAcl
- * Description: Checks an acl to see of we should delete it.
- * Arguments: type - the type of this acl.
- * name - the name of the acl.
+/* Function Name: CheckAce
+ * Description: Checks an ace to see of we should delete it.
+ * Arguments: type - the type of this ace.
+ * name - the name of the ace.
* verbose - query user?
* Returns: none.
*/
void
-CheckAcl(type, name, verbose)
+CheckAce(type, name, verbose)
char * type, *name;
Bool verbose;
{
char *args[2], buf[BUFSIZ];
- int status, ans;
+ int status;
if ( strcmp(type, "LIST") != 0 )
- return; /* If the acl is not a list the ignore it. */
+ return; /* If the ace is not a list the ignore it. */
args[0] = type;
args[1] = name;
- status = sms_query("get_acl_use", 2, args, NullFunc, (char *) NULL);
+ status = sms_query("get_ace_use", 2, args, NullFunc, (char *) NULL);
if (status != SMS_NO_MATCH)
- return; /* If this query fails the acl will
+ return; /* If this query fails the ace will
not be deleted even if it is empty. */
if (verbose) {
- sprintf(buf, "Delete the unused Access Control List (ACL) %s? ", name);
- ans = YesNoQuestion(buf, TRUE);
- if (ans != TRUE) {
+ sprintf(buf, "Delete the unused Access Control List (ACE) %s? ", name);
+ if ( YesNoQuestion(buf, FALSE) != TRUE) {
Put_message("Aborting Deletion!");
return;
}
}
/*
- * Delete the ACL.
+ * Delete the ACE.
*
* NOTE: Delete list expects only the name of the list to delete in argv[1].
* since, 'args' already satisfies this, there is no need to create
}
-/* Function Name: CheckIfAcl
- * Description: Checks to see if this is an acl of another data object.
+/* Function Name: CheckIfAce
+ * Description: Checks to see if this is an ace of another data object.
* Arguments: name - name of the object.
- * Returns: SUB_ERROR if this list is an acl, or if the query did noe
+ * Returns: SUB_ERROR if this list is an ace, or if the query did noe
* succeed.
*/
int
-CheckIfAcl(name, type, verbose)
+CheckIfAce(name, type, verbose)
char * name, * type;
Bool verbose;
{
char * args[2], buf[BUFSIZ];
- struct qelem *elem, *local;
+ struct qelem *local, *elem;
int status;
elem = NULL;
args[0] = type;
args[1] = name;
- status = sms_query("get_acl_use", 2, args, StoreInfo, (char *) &elem);
-
- if (status == SMS_NO_MATCH)
- return(SUB_NORMAL);
-
- if (status != 0) {
- com_err(program_name, status, " in CheckIfAcl (get_acl_use).");
- return(SUB_ERROR);
- }
- local = elem = QueueTop(elem);
- if (verbose) {
- sprintf(buf, "%s %s %s %s", type, name,
- "is the Access Control List (ACL) for the following data",
- "objects:\n");
- Put_message(buf);
- while (local != NULL) {
- char ** info = (char **) local->q_data;
- Print( CountArgs(info), info, NULL);
- local = local->q_forw;
+ switch (status = sms_query("get_ace_use", 2, args,
+ StoreInfo, (char *) &elem)) {
+ case SMS_NO_MATCH:
+ return(DM_NORMAL);
+ case SMS_SUCCESS:
+ local = elem = QueueTop(elem);
+ if (verbose) {
+ sprintf(buf, "%s %s %s %s", type, name,
+ "is the Access Control List (ACE) for the following data",
+ "objects:\n");
+ Put_message(buf);
+ while (local != NULL) {
+ char ** info = (char **) local->q_data;
+ Print( CountArgs(info), info, NULL);
+ local = local->q_forw;
+ }
+ Put_message(
+ "The ACE for each of these items must be changed before");
+ sprintf(buf,"the %s %s can be deleted.\n", type, name);
+ Put_message(buf);
}
- Put_message("The ACL for each of these items must be changed before");
- sprintf(buf,"the %s %s can be deleted.\n", type, name);
- Put_message(buf);
+ break;
+ default:
+ com_err(program_name, status, " in CheckIfAce (get_ace_use).");
+ return(SUB_ERROR);
}
FreeQueue(elem);
return(SUB_ERROR);
/* Function Name: RemoveItemFromLists
* Description: this function removes a list from all other lists of
* which it is a member.
- * Arguments: name - name of the list.
+ * Arguments: name - name of the item
* elem - a pointer to a queue element. RETURNED
* verbose - verbose mode.
* Returns: SUB_ERROR if there is an error.
{
struct qelem *local;
char *args[10], temp_buf[BUFSIZ];
- int status, ans;
+ register int status;
args[0] = type;
args[1] = name;
*elem = NULL;
/*
- * Get all list of which this list is a member, and store them in a queue.
+ * Get all list of which this item is a member, and store them in a queue.
*/
status = sms_query("get_lists_of_member", 2, args, StoreInfo,
* all these lists.
*/
+ local = *elem = QueueTop(*elem);
if (verbose) {
sprintf(temp_buf, "%s %s is a member of %d other list(s).\n", type,
name, QueueCount(*elem) );
Put_message(temp_buf);
- local = *elem;
while (local != NULL) {
char ** info = (char **) local->q_data;
Print( 1, &info[GLOM_NAME], (char *) NULL);
local = local->q_forw;
}
sprintf(temp_buf,"Remove %s %s from these lists? ", type, name);
- ans = YesNoQuestion(temp_buf, TRUE);
- if (ans < 0 || ans == FALSE) {
+ if (YesNoQuestion(temp_buf, FALSE) != TRUE) {
Put_message("Aborting...");
FreeQueue(*elem);
+ *elem = NULL;
return(SUB_ERROR);
}
}
*/
local = *elem;
- args[DM_LIST] = name;
+ args[DM_MEMBER] = name;
args[DM_TYPE] = type;
while (local != NULL) {
char ** info = (char **) local->q_data;
- args[DM_MEMBER] = info[GLOM_NAME];
+ args[DM_LIST] = info[GLOM_NAME];
if ( (status = sms_query("delete_member_from_list",
3, args, Scream, NULL)) != 0) {
com_err(program_name, status, " in delete_member\nAborting\n");
{
char buf[BUFSIZ], *args[10];
struct qelem *local, *elem = NULL;
- int status, ans;
-
+ int status;
+ Bool one_member;
/*
* Get the members of this list.
*/
-
status = sms_query("get_members_of_list", 1, &name, StoreInfo,
(char *) &elem);
if (status == SMS_NO_MATCH)
com_err(program_name, status, " in DeleteList (get_members_of_list).");
return(SUB_ERROR);
}
-
/*
* If verbose mode, then ask the user if we should delete.
*/
local = elem = QueueTop(elem);
if (verbose) {
- sprintf(buf, "List %s has %d member(s):", name, QueueCount(elem) );
+ one_member = (QueueCount(elem) == 1);
+ sprintf(buf, "List %s has %d member%s:", name, QueueCount(elem),
+ one_member ? "" : "s");
Put_message(buf);
while (local != NULL) {
char ** info = (char **) local->q_data;
Print( CountArgs(info), info, NULL);
local = local->q_forw;
}
- sprintf(buf, "Remove these member(s) from list %s? ", name);
- ans = YesNoQuestion(buf, TRUE);
- if (ans < 0 || ans == FALSE) {
+ sprintf(buf, "Remove th%s member%s from list %s? ",
+ one_member ? "is" : "ese", one_member ? "" : "s", name);
+ if ( YesNoQuestion(buf, FALSE) != TRUE) {
Put_message("Aborting...");
FreeQueue(elem);
return(SUB_ERROR);
}
}
-
/*
* Perform The Removal.
*/
-
local = elem;
args[0] = name;
while (local != NULL) {
return(SUB_NORMAL);
}
-
/* Function Name: DeleteUserGroup
* Description: Deletes the list given by name if it exists.
* intended to be used to delete user groups
if (status == 0) {
if (verbose) {
sprintf(buf, "There is also a list named %s, delete it?", name);
- ans = YesNoQuestion(buf, TRUE);
+ ans = YesNoQuestion(buf, FALSE);
if (ans == FALSE) {
Put_message("Leaving group alone.");
return(SUB_NORMAL);
char * name;
Bool verbose;
{
- int status, ans;
+ int status;
char buf[BUFSIZ];
- status = sms_query("get_filesystem_by_label", 1, &name, NullFunc,
- (char *) NULL);
- if (status == SMS_NO_MATCH)
- return(SUB_NORMAL);
- if (status == 0) {
+ switch (status = sms_query("get_filesys_by_label", 1, &name, NullFunc,
+ (char *) NULL)) {
+ case SMS_NO_MATCH:
+ break;
+ case SMS_SUCCESS:
if (verbose) {
sprintf(buf, "Delete the filesystem named %s (y/n)?", name);
- ans = YesNoQuestion(buf, TRUE);
- if (ans != TRUE) {
+ switch (YesNoQuestion(buf, FALSE)) {
+ case FALSE:
+ Put_message("Filesystem Not Deleted, continuing...\n");
+ return(SUB_NORMAL);
+ case TRUE:
+ break;
+ default:
Put_message("Filesystem Not Deleted, aborting...\n\n");
return(SUB_ERROR);
}
}
- if ( (status = sms_query("delete_filesystem", 1, &name, Scream,
- (char *) NULL) ) != 0) {
- com_err(program_name, status, " in delete_filesystem).");
+ if ( (status = sms_query("delete_filesys", 1, &name, Scream,
+ (char *) NULL) ) != SMS_SUCCESS) {
+ com_err(program_name, status, " in delete_filesys.");
return(SUB_ERROR);
}
- return(SUB_NORMAL);
+ else
+ Put_message("Filesystem Successfully Deleted.");
+ break;
+ default:
+ com_err(program_name, status, " in get_filesystem_by_label).");
+ return(SUB_ERROR);
}
- com_err(program_name, status, " in get_filesystem_by_label).");
- return(SUB_ERROR);
+ return(SUB_NORMAL);
}
-/* Function Name: DeleteAllUserQuotas
- * Description: Deletes all quotas for a given user.
- * Arguments: name - name of the user.
- * verbose - ask before performing deletion.
- * Returns: SUB_NORMAL if no quotas, or all quotas removed.
+/* Function Name: RealDeleteUser
+ * Description: Just Deletes the user.
+ * Arguments: name - name of User to delete
+ * Returns: SUB_ERROR if the deletion failed.
*/
-int
-DeleteAllUserQuotas(name, verbose)
+static int
+RealDeleteUser(name)
char * name;
-int verbose;
{
- int status, ans;
- char buf[BUFSIZ], *args[10];
- struct qelem *local, *elem = NULL;
-
- status = sms_query("get_nfs_quotas_by_user", 1, &name, StoreInfo,
- (char *) &elem);
- if (status == SMS_NO_MATCH)
- return(SUB_NORMAL);
- if (status != 0) {
- com_err(program_name, status, " in delete_filesystem.");
+ char buf[BUFSIZ];
+ int status;
+
+ if ( (status = sms_query("delete_user", 1, &name, Scream,
+ (char *) NULL)) != SMS_SUCCESS) {
+ com_err(program_name, status, ": user not deleted");
return(SUB_ERROR);
}
- local = elem = QueueTop(elem);
- if (verbose) {
- sprintf(buf, "User %s has quotas on the following filsystems:");
- Put_message(buf);
- while (local != NULL) {
- char ** info = (char **) local->q_data;
- sprintf(buf, "Filesystem:\t%s\t\tQuota(in Kb):\t%s",
- info[0], info[4]);
- Put_message(buf);
- local = local->q_forw;
- }
- ans = YesNoQuestion("Remove ** ALL ** these quota entries (y/n)?",
- TRUE);
- if (ans != TRUE) {
- Put_message("Aborting..\n\n");
- return(SUB_ERROR);
- }
- }
- local = elem;
- args[1] = name;
- while (local != elem) {
- char ** info = (char **) local->q_data;
- args[0] = info[0];
- status = sms_query("delete_nfs_quota", 2, args, Scream, (char *) NULL);
- if (status != 0 && status != SMS_NO_MATCH) {
- sprintf(buf,
- "Could not remove quota on filesystem %s. ** ABORTING **",
- args[0]);
- Put_message(buf);
- com_err(program_name, status, (char *) NULL);
- FreeQueue(elem);
- return(SUB_ERROR);
- }
- local = local->q_forw;
- }
- FreeQueue(elem);
+ (void) sprintf(buf, "User %s deleted.", name);
+ Put_message(buf);
return(SUB_NORMAL);
}
* Attempt delete. - will only work if:
* 1) This list has no members.
* 2) This list in a member of no other lists.
- * 3) This list is not an acl of another object.
+ * 3) This list is not an ace of another object.
*/
switch (status = sms_query("delete_list", 1, &name,
* what to do we will query and then do it.
*/
- if ( (CheckIfAcl(name, "list", ask_first) == SUB_NORMAL) &&
+ if ( (CheckIfAce(name, "list", ask_first) == SUB_NORMAL) &&
(RemoveMembersOfList(name, ask_first) == SUB_NORMAL) &&
(RemoveItemFromLists(name, "list",
&member_of, ask_first) == SUB_NORMAL) &&
(RealDeleteList(name) == SUB_NORMAL) )
{ /* if... */
- CheckAcl(list_info[L_ACL_TYPE], list_info[L_ACL_NAME], ask_first);
+ CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first);
local = member_of;
while (local != NULL) {
int argc;
char ** argv;
{
-
-/* Make this handle wildcards. */
-
int status;
char buf[BUFSIZ];
char * name = argv[1]; /* name of the user we are deleting. */
struct qelem *local, *member_of = NULL;
+ if (!ValidName(name))
+ return(DM_NORMAL);
+
if (!Confirm("Are you sure that you want to delete this user?"))
return(DM_NORMAL);
status = sms_query("delete_user", 1, &name, Scream, (char *) NULL);
if (status != SMS_IN_USE && status != 0) {
- com_err(program_name, status, ": list not deleted");
+ com_err(program_name, status, ": user not deleted");
return(DM_NORMAL);
}
if (status == 0) {
/*
* Check:
- * 1) Is the user an ACL of any object in the database?
- * 2) Query - Delete home filesytem.
- * 3) Query - Delete users quota on all machines.
- * 4) Query - Remove user from all list of which he is a member.
+ * 1) Query - Delete home filesytem.
+ * 2) Query - Delete user Group.
+ * 2) Is the user an ACE of any object in the database?
+ * 3) Query - Remove user from all list of which he is a member.
*
* If all these have been accomplished, then attempt to delete the user again.
*/
- if ( (CheckIfAcl(name, "user", TRUE) == SUB_ERROR) ||
- (DeleteHomeFilesys(name, TRUE) == SUB_ERROR) ||
- (DeleteAllUserQuotas(name, TRUE) == SUB_ERROR) ||
+ if ( (DeleteHomeFilesys(name, TRUE) == SUB_ERROR) ||
+ (DeleteUserGroup(name, TRUE) == SUB_ERROR) ||
+ (CheckIfAce(name, "user", TRUE) == SUB_ERROR) ||
(RemoveItemFromLists(name, "user",
&member_of, TRUE) == SUB_ERROR) ||
(RealDeleteUser(name) == SUB_ERROR) ) {
- FreeQueue(member_of);
return(DM_NORMAL);
}
}
/*
- * Query - Delete user group.
* Query - Delete all empty lists created by removing this user from them.
*/
- if (DeleteUserGroup(name, TRUE) == SUB_ERROR) {
- FreeQueue(member_of);
- return(DM_NORMAL);
- }
-
local = member_of;
while (local != NULL) {
char ** info = (char **) local->q_data;
FreeQueue(member_of); /* Free memory and return. */
return(DM_NORMAL);
}
-
-/* Function Name: RealDeleteUser
- * Description: Just Deletes the user.
- * Arguments: name - name of User to delete
- * Returns: SUB_ERROR if the deletion failed.
- */
-
-static int
-RealDeleteUser(name)
-char * name;
-{
- char buf[BUFSIZ];
- int status;
-
- if ( (status = sms_query("delete_user", 1, &name, Scream,
- (char *) NULL)) == NULL) {
- com_err(program_name, status, ": user not deleted");
- return(SUB_ERROR);
- }
- (void) sprintf(buf, "User %s deleted./n", name);
- Put_message(buf);
- return(SUB_NORMAL);
-}
-
/*
* Local Variables:
#define LIST 0
#define MEMBERS 1
#define GLOM 2
-#define ACL_USE 3
+#define ACE_USE 3
#define DEFAULT_ACTIVE DEFAULT_YES
#define DEFAULT_PUBLIC DEFAULT_YES
#define DEFAULT_MAILLIST DEFAULT_YES
#define DEFAULT_GROUP DEFAULT_NO
#define DEFAULT_GID UNIQUE_GID
-#define DEFAULT_ACL_TYPE "user"
-#define DEFAULT_ACL_NAME (user)
+#define DEFAULT_ACE_TYPE "user"
+#define DEFAULT_ACE_NAME (user)
#define DEFAULT_DESCRIPTION DEFAULT_COMMENT
/* globals only for this file. */
static char current_list[BUFSIZ];
-/* Function Name: PrintListAcl
- * Description: This function prints the list acl information.
+/* Function Name: PrintListAce
+ * Description: This function prints the list ace information.
* Arguments: info - an info structure.
* Returns: none.
*/
static void
-PrintListAcl(info)
+PrintListAce(info)
char ** info;
{
char buf[BUFSIZ];
Put_message(" ");
- sprintf(buf, "Item Administered: %-20s Name: %s", info[ACL_TYPE],
- info[ACL_NAME]);
+ sprintf(buf, "Item Administered: %-20s Name: %s", info[ACE_TYPE],
+ info[ACE_NAME]);
Put_message(buf);
}
else
Put_message("This list is NOT a Group.");
- if (strcmp(info[L_ACL_TYPE],"NONE") == 0)
+ if (strcmp(info[L_ACE_TYPE],"NONE") == 0)
Put_message("This list has no Administrator, how strange?!");
else {
sprintf(buf, "The Administrator of this list is the %s: %s",
- info[L_ACL_TYPE], info[L_ACL_NAME]);
+ info[L_ACE_TYPE], info[L_ACE_NAME]);
Put_message(buf);
}
atoi(info[L_PUBLIC]) ? "public" : "private",
atoi(info[L_HIDDEN]) ? "hidden" : "visible");
(void) Put_message(buf);
- (void) sprintf(buf, "Last modification at %s, by %s using the program %s",
- info[L_MODTIME], info[L_MODBY], info[L_MODWITH]);
+ sprintf(buf, MOD_FORMAT, info[L_MODBY], info[L_MODTIME], info[L_MODWITH]);
(void) Put_message(buf);
}
return (NULL);
}
break;
- case ACL_USE:
+ case ACE_USE:
args[0] = name1;
args[1] = name2;
- if ( (status = sms_query("get_acl_use", 2, args,
+ if ( (status = sms_query("get_ace_use", 2, args,
StoreInfo, (char *) &elem)) != 0) {
- com_err(program_name, status, " in get_acl_use");
+ com_err(program_name, status, " in get_ace_use");
return (NULL);
}
break;
if (name) {
newname = Strsave(info[L_NAME]);
- GetValueFromUser("The new name for this list.", &newname);
+ GetValueFromUser("The new name for this list", &newname);
}
- GetValueFromUser("Is this list active (1/0): ", &info[L_ACTIVE]);
- GetValueFromUser("Is this list public (1/0): ", &info[L_PUBLIC]);
- GetValueFromUser("Is this list hidden (1/0): ", &info[L_HIDDEN]);
- GetValueFromUser("Is this a maillist (1/0): ", &info[L_MAILLIST]);
- GetValueFromUser("is this a group (1/0): ", &info[L_GROUP]);
+ GetYesNoValueFromUser("Is this an active list", &info[L_ACTIVE]);
+ GetYesNoValueFromUser("Is this a public list", &info[L_PUBLIC]);
+ GetYesNoValueFromUser("Is this a hidden list", &info[L_HIDDEN]);
+ GetYesNoValueFromUser("Is this a maillist", &info[L_MAILLIST]);
+ GetYesNoValueFromUser("is this a group", &info[L_GROUP]);
if (atoi(info[L_GROUP]))
GetValueFromUser("What is the GID for this group.", &info[L_GID]);
GetValueFromUser("What Type of Administrator (none, user, list): ",
- &info[L_ACL_TYPE]);
- if ( (strcmp(info[L_ACL_TYPE], "USER") == 0) ||
- (strcmp(info[L_ACL_TYPE], "user") == 0) )
+ &info[L_ACE_TYPE]);
+ if ( (strcmp(info[L_ACE_TYPE], "USER") == 0) ||
+ (strcmp(info[L_ACE_TYPE], "user") == 0) )
GetValueFromUser("Who will be the administrator of this list: ",
- &info[L_ACL_NAME]);
- if ( (strcmp(info[L_ACL_TYPE], "LIST") == 0) ||
- (strcmp(info[L_ACL_TYPE], "list") == 0) )
+ &info[L_ACE_NAME]);
+ if ( (strcmp(info[L_ACE_TYPE], "LIST") == 0) ||
+ (strcmp(info[L_ACE_TYPE], "list") == 0) )
GetValueFromUser("Which group will be the administrator of this list: ",
- &info[L_ACL_NAME]);
+ &info[L_ACE_NAME]);
GetValueFromUser("Description: ", &info[L_DESC]);
FreeAndClear(&info[L_MODTIME], TRUE);
info[L_MAILLIST] = Strsave(DEFAULT_MAILLIST);
info[L_GROUP] = Strsave(DEFAULT_GROUP);
info[L_GID] = Strsave(DEFAULT_GID);
- info[L_ACL_TYPE] = Strsave(DEFAULT_ACL_TYPE);
- info[L_ACL_NAME] = Strsave(DEFAULT_ACL_NAME);
+ info[L_ACE_TYPE] = Strsave(DEFAULT_ACE_TYPE);
+ info[L_ACE_NAME] = Strsave(DEFAULT_ACE_NAME);
info[L_DESC] = Strsave(DEFAULT_DESCRIPTION);
info[L_MODTIME] = info[L_MODBY] = info[L_MODWITH] = info[L_END] = NULL;
return(info);
{
char temp_buf[BUFSIZ];
char *list_name = argv[1];
-
+ register int stat;
+
if (!ValidName(list_name))
return(DM_QUIT);
if (YesNoQuestion(temp_buf, TRUE) != TRUE )
return(DM_QUIT);
}
+ else
+ /* All we want to know is if it exists. */
+ switch( (stat = sms_query("count_members_of_list", 1, argv + 1,
+ NullFunc, (char *) NULL))) {
+ case SMS_SUCCESS:
+ break;
+ case SMS_LIST:
+ Put_message("This list does not exist.");
+ return(DM_QUIT);
+ case SMS_ACCESS:
+ Put_message("You are not allowed to view this list.");
+ return(DM_QUIT);
+ default:
+ com_err(program_name, stat, " in get_list_info");
+ return(DM_QUIT);
+ }
(void) sprintf(temp_buf,
"Change/Display membership of '%s'", list_name);
}
name = Strsave(buf);
- top = GetListInfo(ACL_USE, type, name);
- Loop(top, PrintListAcl);
+ top = GetListInfo(ACE_USE, type, name);
+ Loop(top, PrintListAce);
FreeQueue(top);
return (DM_NORMAL);
"NFS Maintenence",
5,
{
- { ShowNFSService, NULLMENU, 3, {
+ { ShowNFSService, NULLMENU, 2, {
{ "show", "Show an NFS server" },
{ "machine", "Machine Name: "},
- { "device", "Directory: "}
} },
- { AddNFSService, NULLMENU, 3, {
+ { AddNFSService, NULLMENU, 2, {
{ "add", "Add NFS server" },
{ "machine", "Machine Name: "},
- { "device", "Directory: "}
} },
- { UpdateNFSService, NULLMENU, 3, {
+ { UpdateNFSService, NULLMENU, 2, {
{ "update", "Update NFS server"},
{ "machine", "Machine Name: "},
- { "device", "Directory: "}
} },
- { DeleteNFSService, NULLMENU, 3, {
+ { DeleteNFSService, NULLMENU, 2, {
{ "delete", "Delete NFS server"},
{"machine", "Machine Name: "},
- {"device", "Directory: "}
} },
SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode),
/* SIMPLEFUNC("help", "Help", NFSHelp), */
* Usermaint menu.
*/
+Menu usermaint_pobox_menu = {
+ NULLFUNC,
+ NULLFUNC,
+ "Edit User Post Office Boxes",
+ 3,
+ {
+ {GetUserPOBox, NULLMENU, 2, {
+ {"show", "Show a user's post office box"},
+ {"login name", "login name: "}
+ } },
+ {SetUserPOBox, NULLMENU, 2, {
+ {"set", "Set (Add or Change) a user's post office box"},
+ {"login name", "login name: "}
+ } },
+ {RemoveUserPOBox, NULLMENU, 2, {
+ {"remove", "Remove a user's post office box"},
+ {"login name", "login name: "}
+ } },
+ }
+};
+
Menu usermaint_quota_menu = {
NULLFUNC,
NULLFUNC,
- "Edit User Quotas and Server Machines",
+ "Edit User and Default Quotas",
6,
{
SIMPLEFUNC("shdef", "Show default user quota (in KB)", ShowDefaultQuota),
- {ShowUserQuota, NULLMENU, 2, {
- {"shquota", "Show a user's quota (in KB)"},
- {"login", "Login name: "}
- } },
{ChangeDefaultQuota, NULLMENU, 2, {
{"chdef", "Change default user quota"},
{"quota", "New quota (in KB): "}
} },
- {ChangeUserQuota, NULLMENU, 2, {
- {"chquota", "Change a user's disk quota"},
- {"user", "Login name: "}
- } },
- {AddUserLocker, NULLMENU, 5, {
- {"create", "Create a quota & locker for a user"},
- {"login", "User's login name: "},
- {"machine", "Server host name: "},
- {"device", "Directory on host: /[dir]/[login] "},
- {"quota", "Quota in KB: "}
- } },
- {DeleteUserLocker, NULLMENU, 2, {
- {"del", "Delete a user's quota & locker - BROKEN 6/10/88 CDP"},
- {"login", "User's login: "}
- } }
+ SIMPLEFUNC("shquota", "Show a user's disk quota on a filesytem",
+ ShowUserQuota),
+ SIMPLEFUNC("addquota", "Add a new disk quota for user on a filesytem",
+ AddUserQuota),
+ SIMPLEFUNC("chquota", "Change a user's disk quota on a filesytem",
+ ChangeUserQuota),
+ SIMPLEFUNC("rmquota", "Remove a user's disk quota on a filesytem",
+ RemoveUserQuota),
}
};
NULLFUNC,
NULLFUNC,
"SMS User Maintenance",
- 8,
+ 9,
{
{ShowUserByLogin, NULLMENU, 2, {
{"login", "Show user information by login name"},
{"login name", "Desired login name: "}
} },
{ShowUserByName, NULLMENU, 3, {
- {"full", "Show user information by name"},
+ {"name", "Show user information by name"},
{"first", "First name: "},
{"last", "Last name: "}
} },
{ShowUserByClass, NULLMENU, 2, {
- {"login", "Show names of users in a given class"},
+ {"class", "Show names of users in a given class"},
{"login name", "Desired class: "}
} },
- {ModifyUser, NULLMENU, 2, {
+ {UpdateUser, NULLMENU, 2, {
{"modify", "Change all user fields"},
{"login", "Login name: "}
} },
/* SIMPLEFUNC("chpw", "Change a user's password", change_user_password), */
- {ChangeUserPOBox, NULLMENU, 2, {
- {"chpobox", "Change a user's post office box"},
- {"login name", "login name: "}
- } },
-/* {enter_user, NULLMENU, 6, {
- {"enter", "Enter unregistered user"},
- {"first", "User's first name: "},
- {"middle", "User's middle initial: "},
- {"last", "User's last name: "},
- {"mit_id", "User's MIT ID: "},
- {"mit_year", "User's MIT year: "}
- } },
- {reg_user, NULLMENU, 5, {
- {"register", "Register unregistered user"},
- {"first", "User's first name: "},
- {"last", "User's last name: "},
- {"mit_id", "User's MIT ID: "},
- {"login", "Login name to assign: "}
- } },
- */
+ SIMPLEFUNC("adduser", "Add a new user to the database",
+ AddNewUser),
+ SIMPLEFUNC("register", "Register a user", RegisterUser),
{DeleteUser, NULLMENU, 2, {
{"delete", "Delete user"},
{"login", "Login name: "}
{"udelete", "Delete user by uid"},
{"uid", "User ID (not MIT ID!): "}
} },
+ SUBMENU("pobox", "User PO Boxes", &usermaint_pobox_menu),
SUBMENU("quota", "User Quotas", &usermaint_quota_menu),
}
};
#define TYPE_NFS "NFS"
#define DEFAULT_DIR "/mit"
-#define DEFAULT_STATUS "1"
+#define DEFAULT_DEVICE "ra0a"
+#define DEFAULT_STATUS DEFAULT_YES /* active. */
#define DEFAULT_ALLOC "0"
-#define DEFAULT_SIZE "400000"
+#define DEFAULT_SIZE "0"
+
+/* Function Name: UpdatePrint
+ * Description: store a useful string for updates to print.
+ * Arguments: info - info about NFS service stored in array of strings.
+ * Returns: useful string.
+ */
+
+static char *
+UpdatePrint(info)
+char ** info;
+{
+ char temp_buf[BUFSIZ];
+ sprintf(temp_buf, "Machine %s Directory %s",
+ info[NFS_NAME], info[NFS_DIR]);
+ return(Strsave(temp_buf)); /* Small memory leak here, but no good way
+ to avoid it that I see. */
+}
/* Function Name: PrintNFSInfo
* Description: Prints NFS Physical service information.
* Arguments: info - the information.
- * Returns: none.
+ * Returns: directory of this nfs server, for DeleteNFSService().
*/
-void
+static char *
PrintNFSInfo(info)
char ** info;
{
- char temp_buf[BUFSIZ];
+ char buf[BUFSIZ], status_buf[BUFSIZ];
int status = atoi(info[NFS_STATUS]);
+ Bool is_one = FALSE;
- sprintf(temp_buf,"Machine: %s,\tDirectory: %s,\tDevice: %s",
+ status_buf[0] = '\0'; /* clear string. */
+
+ if (status & SMS_FS_STUDENT) {
+ strcat(status_buf, "Student");
+ is_one = TRUE;
+ }
+ if (status & SMS_FS_FACULTY) {
+ if (is_one)
+ strcat(status_buf, " and ");
+ strcat(status_buf, "Faculty");
+ is_one = TRUE;
+ }
+ if (status & SMS_FS_STAFF) {
+ if (is_one)
+ strcat(status_buf, " and ");
+ strcat(status_buf, "Staff");
+ is_one = TRUE;
+ }
+ if (status & SMS_FS_MISC) {
+ if (is_one)
+ strcat(status_buf, " and ");
+ strcat(status_buf, "Miscellaneous");
+ }
+ /* Add another type here. */
+
+ if (status_buf[0] == '\0')
+ strcat(status_buf, "-- None --");
+
+ Put_message("");
+ sprintf(buf,"Machine: %-20s Directory: %-15s Device: %s",
info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]);
- Put_message(temp_buf);
- sprintf(temp_buf, "Status: %s,\tQuota Allocated: %s.\tSize: %s",
- status ? "Active" : "Inactive", info[NFS_ALLOC], info[NFS_SIZE]);
- Put_message(temp_buf);
- sprintf(temp_buf, "Last Modification by %s at %s with %s.",
- info[U_MODBY], info[U_MODTIME], info[U_MODWITH]);
- Put_message(temp_buf);
+ Put_message(buf);
+ sprintf(buf, "Status: %s", status_buf);
+ Put_message(buf);
+ sprintf(buf, "Quota Allocated: %-17s Size: %s",
+ info[NFS_ALLOC], info[NFS_SIZE]);
+ Put_message(buf);
+ sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME],
+ info[NFS_MODWITH]);
+ Put_message(buf);
+ return(info[NFS_DIR]);
}
+
/* Function Name: AskNFSInfo.
* Description: This function askes the user for information about a
* machine and saves it into a structure.
{
/* Also need name of the machine in this structure. */
- GetValueFromUser("Directory for filesystem:", &info[NFS_DIR]);
GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]);
-
- Put_message("\nTypes: Student, Faculty, Project, Staff, and Other.\n");
- GetValueFromUser("Please enter one or more of the above types:"
- ,&info[NFS_STATUS]);
-
+ GetFSTypes(&info[NFS_STATUS]);
GetValueFromUser("Allocated Space for this filsystem:",&info[NFS_ALLOC]);
GetValueFromUser("Size of this Filsystem:",&info[NFS_SIZE]);
return(info);
}
+/* Function Name: GetDirName
+ * Description: get the directory name.
+ * Arguments: none.
+ * Returns: the directory name.
+ */
+
+static char *
+GetDirName()
+{
+ char buf[BUFSIZ];
+ if (Prompt_input("Directory: ", buf, BUFSIZ) == -1)
+ return(NULL);
+ return(Strsave(buf));
+}
+
/* Function Name: ShowNFSService
* Description: This function prints all exported partitions.
* Arguments: argc, argv - argv[1] - name of machine.
- * argv[2] - name of directroy.
* Returns: DM_NORMAL.
*/
char **argv;
{
register int stat;
- struct qelem * top, *elem = NULL;
+ struct qelem *elem = NULL;
+ char *args[10];
+
+ if (!ValidName(argv[1]))
+ return(DM_NORMAL);
- if ( (stat = sms_query("get_nfsphys", 2, argv + 1,
- StoreInfo, (char *) &elem)) != 0)
+ args[0] = CanonicalizeHostname(argv[1]);
+ if ( (args[1] = GetDirName()) == NULL)
+ return(DM_NORMAL);
+
+ if ( (stat = sms_query("get_nfsphys", 2, args,
+ StoreInfo, (char *) &elem)) != SMS_SUCCESS)
com_err(program_name, stat, " in ShowNFSServices.");
+ free(args[1]); /* prevents memory leaks. */
- top = elem;
- while (elem != NULL) {
- char ** info = (char **) elem->q_data;
- PrintNFSInfo(info);
- elem = elem->q_forw;
- }
- FreeQueue(top);
+ elem = QueueTop(elem);
+ Loop(elem, (void *) PrintNFSInfo);
+
+ FreeQueue(elem);
return (DM_NORMAL);
}
/* Function Name: AddNFSService
* Description: Adds a new partition to the nfsphys relation
- * Arguments: arc, argv -
- * argv[1] - machine name.
- * argv[2] - directory.
+ * Arguments: arc, argv - argv[1] - machine name.
* Returns: DM_NORMAL.
*/
char **argv;
int argc;
{
- char **args;
- static char *info[MAX_ARGS_SIZE];
+ char **add_args, *args[10];
+ char *info[MAX_ARGS_SIZE];
int stat;
+
+ args[0] = CanonicalizeHostname(argv[1]);
+ if ( (args[1] = GetDirName()) == NULL)
+ return(DM_NORMAL);
+
+ if (!ValidName(args[0]) || !ValidName(args[1]))
+ return(DM_NORMAL);
- if ( (stat = sms_query("get_nfsphys", 2, argv + 1,
- NullFunc, (char *) NULL)) == 0) {
+ if ( (stat = sms_query("get_nfsphys", 2, args,
+ NullFunc, (char *) NULL)) == SMS_SUCCESS)
Put_message("This service already exists.");
- if (stat != SMS_NO_MATCH)
- com_err(program_name, stat, " in get_nfsphys.");
- }
+ if (stat != SMS_NO_MATCH)
+ com_err(program_name, stat, " in get_nfsphys.");
- if ( (info[NFS_NAME] = CanonicalizeHostname(argv[1])) == NULL) {
- Put_message("Unknown host, try again...");
- return(DM_NORMAL);
- }
-
- info[NFS_NAME] = Strsave(info[NFS_NAME]);
- info[NFS_DEVICE] = Strsave(argv[2]);
- info[NFS_DIR] = Strsave(DEFAULT_DIR);
+ info[NFS_NAME] = Strsave(args[0]);
+ info[NFS_DIR] = args[1]; /* already saved. */
+ info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE);
info[NFS_STATUS] = Strsave(DEFAULT_STATUS);
info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC);
info[NFS_SIZE] = Strsave(DEFAULT_SIZE);
- info[NFS_SIZE + 1] = NULL; /* NULL terminate. */
+ info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL;
+ info[NFS_END] = NULL;
- args = AskNFSInfo(info);
+ add_args = AskNFSInfo(info);
- if ((stat = sms_query("add_nfsphys", CountArgs(args), args,
+ if ((stat = sms_query("add_nfsphys", CountArgs(add_args), add_args,
Scream, (char *) NULL)) != 0)
com_err(program_name, stat, " in AdsNFSService");
return (DM_NORMAL);
}
+/* Function Name: RealUpdateNFSService
+ * Description: performs the actual update of the nfs service.
+ * Arguments: info - info about NFS service stored in array of strings.
+ * junk - an unused boolean.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+RealUpdateNFSService(info, junk)
+char ** info;
+Bool junk;
+{
+ char ** args;
+ register int stat;
+
+ args = AskNFSInfo(info);
+ if ((stat = sms_query("update_nfsphys", CountArgs(args), args,
+ Scream, (char *)NULL)) != SMS_SUCCESS)
+ com_err(program_name, stat, (char *) NULL);
+}
+
/* Function Name: UpdateNFSService
* Description: Update the values for an nfsphys entry.
- * Arguments: argc, argv -
- * argv[1] - machine name.
- * argv[2] - directory.
+ * Arguments: argc, argv - argv[1] - machine name.
* Returns: DM_NORMAL.
*/
int argc;
{
register int stat;
- Bool update, one_service;
- char **args, **info, buf[BUFSIZ];
- struct qelem *elem, *top;
- elem = NULL;
+ struct qelem *elem = NULL;
+ char * args[10];
- if ( (argv[1] = CanonicalizeHostname(argv[1])) == NULL) {
- Put_message("Unknown host, try again...");
+ if (!ValidName(argv[1]))
return(DM_NORMAL);
- }
- if ( (stat = sms_query("get_nfsphys", 2, argv + 1,
- StoreInfo, (char *) &elem)) != 0) {
+ args[0] = CanonicalizeHostname(argv[1]);
+ if ( (args[1] = GetDirName()) == NULL)
+ return(DM_NORMAL);
+
+ if ( (stat = sms_query("get_nfsphys", 2, args,
+ StoreInfo, (char *) &elem)) != SMS_SUCCESS) {
com_err(program_name, stat, " in UpdateNFSService.");
return (DM_NORMAL);
}
+ free(args[1]); /* stop memory leaks. */
- top = elem = QueueTop(elem);
- one_service = ( QueueCount(top) == 1 );
- while (elem != NULL) {
- info = (char **) elem->q_data;
- if (!one_service) { /* If more than one then query through them. */
- sprintf(buf,"Update - %s\tDirectory: %s? (y/n/q)", info[NFS_NAME],
- info[NFS_DIR]);
- switch( YesNoQuitQuestion(buf, FALSE)) {
- case TRUE:
- update = TRUE;
- break;
- case FALSE:
- update = FALSE;
- break;
- default:
- FreeQueue(top);
- Put_message("Aborting update.");
- return(DM_NORMAL);
- }
- }
- else
- update = TRUE;
-
- if (update) { /* actually perform update */
- args = AskNFSInfo(info);
- if ((stat = sms_query("update_nfsphys", CountArgs(args), args,
- Scream, (char *)NULL)) != 0)
- com_err(program_name, stat, (char *) NULL);
- }
- elem = elem->q_forw;
- }
+ elem = QueueTop(elem);
+ QueryLoop(elem, UpdatePrint, RealUpdateNFSService,
+ "Update NFS Service for");
- FreeQueue(top);
+ FreeQueue(elem);
return (DM_NORMAL);
}
+/* Function Name: FSPartPrint
+ * Description: print filesystem partition usage.
+ * Arguments: info - the filesystem information.
+ * Returns: none.
+ */
+
+static void
+FSPartPrint(info)
+char ** info;
+{
+ char buf[BUFSIZ];
+ sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]);
+ Put_message(buf);
+}
+
+/* Function Name: RealDeleteNFSService
+ * Description: Actually Deletes the filesystem (some checks are made).
+ * Arguments: info - info about NFS service stored in array of strings.
+ * one_item - if TRUE then only one item on the queue, and
+ * we should confirm.
+ * Returns: none.
+ */
+
+static void
+RealDeleteNFSService(info, one_item)
+char ** info;
+Bool one_item;
+{
+ char temp_buf[BUFSIZ], *args[10];
+ struct qelem *elem= NULL;
+ register int stat;
+
+ sprintf(temp_buf,
+ "Are you sure that you want to delete the %s directory on %s",
+ info[NFS_DIR],info[NFS_NAME]);
+
+/*
+ * Check to be sure that it is not used by any of the nfs packs.
+ */
+
+ if (!one_item || Confirm(temp_buf)) {
+ args[0] = info[NFS_NAME];
+ args[1] = info[NFS_DIR];
+ args[2] = NULL;
+ switch(stat = sms_query("get_filesys_by_nfsphys", CountArgs(args),
+ args, StoreInfo, &elem)) {
+ case SMS_NO_MATCH: /* it is unused, delete it. */
+ if ( (stat = sms_query("delete_nfsphys", 2, info, Scream,
+ (char *) NULL )) != SMS_SUCCESS)
+ com_err(program_name, stat, " in DeleteNFSService");
+ else
+ Put_message("Physical Filesystem Deleted.");
+ break;
+ case SMS_SUCCESS: /* it is used, print filesys's that use it. */
+ elem = QueueTop(elem);
+ Put_message("The following fileystems are using this partition,");
+ Put_message("and must be removed before it can be deleted.");
+ Put_message("");
+ Loop(elem, FSPartPrint);
+
+ FreeQueue(elem);
+ Put_message("");
+ break;
+ default:
+ com_err(program_name, stat, " while checking usage of partition");
+ }
+ }
+ else
+ Put_message("Physical filesystem not deleted.");
+}
+
/* Function Name: DeleteNFSService
* Description: Delete an nfsphys entry.
- * Arguments: argc, argv - name of file system in argv[1].
- * directory of file system in argv[2].
+ * Arguments: argc, argv - name of the machine in argv[1].
* Returns: DM_NORMAL.
*/
char **argv;
{
register int stat;
- struct qelem *top, *elem = NULL;
- char * dir = argv[2];
- int length;
- Bool delete_ok = TRUE;
+ struct qelem *elem = NULL;
+ char * args[10];
- argv[1] = CanonicalizeHostname(argv[1]);
+ if (!ValidName(argv[1]))
+ return(DM_NORMAL);
+
+ args[0] = CanonicalizeHostname(argv[1]);
+ if ( (args[1] = GetDirName()) == NULL)
+ return(DM_NORMAL);
- stat = sms_query("get_nfsphys", 2, argv + 1, NullFunc, (char *) NULL);
- if (stat == SMS_NO_MATCH) {
+ switch(stat = sms_query("get_nfsphys", 2, args,
+ StoreInfo, (char *) &elem)) {
+ case SMS_NO_MATCH:
Put_message("This filsystem does not exist!");
return(DM_NORMAL);
- }
- if (stat) {
+ case SMS_SUCCESS:
+ break;
+ default:
com_err(program_name, stat, " in DeleteNFSService");
return(DM_NORMAL);
}
-
- stat = sms_query("get_filesys_by_machine", 1, argv + 1, StoreInfo,
- &elem);
- if (stat && stat != SMS_NO_MATCH)
- com_err(program_name, stat, " while checking usage of partition");
-
- length = strlen( dir );
- top = elem = QueueTop(elem);
- while (elem != NULL) {
- char buf[BUFSIZ];
- char ** info = (char ** ) elem->q_data;
- if ( (strcmp(info[FS_TYPE], TYPE_NFS) == 0) &&
- (strcmp(info[FS_PACK], dir, length) == 0) ) {
- sprintf(buf, "Filesystem %s uses that partition", info[FS_NAME]);
- Put_message(buf);
- delete_ok = FALSE;
- }
- elem = elem->q_forw;
- }
+ free(args[1]); /* stop memory leaks, in your neighborhood. */
- if ( delete_ok &&
- Confirm("Do you really want to delete this Filesystem? (y/n) ")) {
- if ( (stat = sms_query("delete_nfsphys", 2, argv + 1,
- Scream, (char *) NULL )) !=0 )
- com_err(program_name, stat, " in DeleteNFSService");
- }
- else
- Put_message("Operation Aborted.\n");
+ QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService,
+ "Delete the Physical Filesystem on Directory");
- FreeQueue(top);
+ FreeQueue(elem);
return(DM_NORMAL);
-}
-
+}
/*
* Local Variables:
#include <stdio.h>
#include <strings.h>
-#include <ctype.h>
#include <sms.h>
#include <menu.h>
#define LOGIN 0
#define UID 1
#define BY_NAME 2
-#define QUOTA 3
-#define CLASS 4
+#define CLASS 3
-static void PrintQuota(); /* prints Quota info. */
-static void PrintUserInfo(); /* prints User info. */
-static int PrintPOBoxes(); /* prints PO Box information. */
+/* Function Name: PrintUserName
+ * Description: Print name of a user.
+ * Arguments: info - the information about a user.
+ * Returns: none.
+ */
+
+static void
+PrintUserName(info)
+char ** info;
+{
+ char buf[BUFSIZ], print_buf[BUFSIZ];
+ sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
+ sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]);
+ Put_message(print_buf);
+}
+
+/* Function Name: PrintUserInfo
+ * Description: Prints Information about a user.
+ * Arguments: info - an argument list with the user information
+ * in it.
+ * Returns: none
+ */
+
+static void
+PrintUserInfo(info)
+char ** info;
+{
+ char name[BUFSIZ], buf[BUFSIZ];
+
+ sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
+ sprintf(buf, "Login name: %-10s Full name: %s", info[U_NAME], name);
+ Put_message(buf);
+ sprintf(buf, "User id: %-13s Login shell %-15s Class: %s",
+ info[U_UID], info[U_SHELL], info[U_CLASS]);
+ Put_message(buf);
+ sprintf(buf, "Account is: %-10s Encrypted MIT ID number: %s",
+ atoi(info[U_STATE]) ? "active" : "inactive", info[U_MITID]);
+ Put_message(buf);
+ sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME],info[U_MODWITH]);
+ Put_message(buf);
+}
+
+/* Function Name: SetUserDefaults
+ * Description: Sets the default values for add user.
+ * Arguments: info - a blank user info array of char *'s.
+ * Returns: args - the filled info structure.
+ */
+
+static char **
+SetUserDefaults(info)
+char ** info;
+{
+ info[U_NAME] = Strsave(UNIQUE_LOGIN);
+ info[U_UID] = Strsave(UNIQUE_UID);
+ info[U_SHELL] = Strsave(DEFAULT_NONE);
+ info[U_LAST] = Strsave(DEFAULT_NONE);
+ info[U_FIRST] = Strsave(DEFAULT_NONE);
+ info[U_MIDDLE] = Strsave(DEFAULT_NONE);
+ info[U_STATE] = Strsave(DEFAULT_NO);
+ info[U_MITID] = Strsave(DEFAULT_NONE);
+ info[U_CLASS] = Strsave(DEFAULT_NONE);
+ info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
+ return(info);
+}
/* Function Name: AskUserInfo.
* Description: This function askes the user for information about a
char ** info;
Bool name;
{
- char temp_buf[BUFSIZ], *newname;
-
- sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
- Put_message(temp_buf);
+ char temp_buf[BUFSIZ], *newname, *temp_ptr;
+ if (name) {
+ sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
+ Put_message(temp_buf);
+ }
if (name) {
newname = Strsave(info[U_NAME]);
- GetValueFromUser("The new login name for this user.", &newname);
+ GetValueFromUser("The new login name for this user", &newname);
}
- GetValueFromUser("User's UID:", &info[U_UID]);
- GetValueFromUser("User's shell:", &info[U_SHELL]);
- GetValueFromUser("User's last name:", &info[U_LAST]);
- GetValueFromUser("User's first name:", &info[U_FIRST]);
- GetValueFromUser("User's middle name:", &info[U_MIDDLE]);
- GetValueFromUser("User's status:", &info[U_STATE]);
- GetValueFromUser("User's MIT ID number:", &info[U_MITID]);
- RemoveHyphens(info[U_MITID]); /* zap'em */
- GetValueFromUser("User's MIT Year (class):", &info[U_CLASS]);
+ else
+ GetValueFromUser("Login name for this user", &info[U_NAME]);
+
+ GetValueFromUser("User's UID", &info[U_UID]);
+ GetValueFromUser("User's shell", &info[U_SHELL]);
+ GetValueFromUser("User's last name", &info[U_LAST]);
+ GetValueFromUser("User's first name", &info[U_FIRST]);
+ GetValueFromUser("User's middle name", &info[U_MIDDLE]);
+ GetValueFromUser("User's status", &info[U_STATE]);
+ temp_ptr = Strsave(info[U_MITID]);
+ GetValueFromUser("User's MIT ID number", &temp_ptr);
+ if ( strcmp( temp_ptr, info[U_MITID] ) != 0) {
+ RemoveHyphens(temp_ptr); /* zap'em */
+ EncryptMITID(temp_buf, temp_ptr, info[U_FIRST], info[U_LAST]);
+ free(info[U_MITID]);
+ info[U_MITID] = Strsave(temp_buf);
+ }
+ free(temp_ptr);
+ GetValueFromUser("User's MIT Year (class)", &info[U_CLASS]);
FreeAndClear(&info[U_MODTIME], TRUE);
FreeAndClear(&info[U_MODBY], TRUE);
if ( (status = sms_query("get_user_by_login", 1, args,
StoreInfo, (char *) &elem)) != 0) {
com_err(program_name, status,
- " when attempting to get_use_by_login.");
+ " when attempting to get_user_by_login.");
return (NULL);
}
break;
if ( (status = sms_query("get_user_by_uid", 1, args,
StoreInfo, (char *) &elem)) != 0) {
com_err(program_name, status,
- " when attempting to get_use_by_uid.");
+ " when attempting to get_user_by_uid.");
return (NULL);
}
break;
case BY_NAME:
args[0] = name1;
args[1] = name2;
- if ( (status = sms_query("get_user_by_name", 1, args,
+ if ( (status = sms_query("get_user_by_name", 2, args,
StoreInfo, (char *) &elem)) != 0) {
com_err(program_name, status,
- " when attempting to get_use_by_name.");
+ " when attempting to get_user_by_name.");
return (NULL);
}
break;
if ( (status = sms_query("get_user_by_class", 1, args,
StoreInfo, (char *) &elem)) != 0) {
com_err(program_name, status,
- " when attempting to get_use_by_class.");
+ " when attempting to get_user_by_class.");
return (NULL);
}
break;
- case QUOTA:
- args[0] = name1;
- if ( (status = sms_query("get_nquotas_by_user", 1, args,
- StoreInfo, (char *) &elem)) != 0) {
- com_err(program_name, status, " in get_nfs_quotas_by_user");
- return (DM_NORMAL);
- }
- break;
}
return( QueueTop(elem) );
}
-/* -------------------------- Change Menu -------------------------- */
-
-/* Function Name: ModifyUser
- * Description: Modify some of the information about a user.
- * Arguments: argc, argv - login name of the user in argv[1].
+/* Function Name: AddNewUser
+ * Description: Adds a new user to the database.
+ * Arguments: none.
* Returns: DM_NORMAL.
*/
/* ARGSUSED */
int
-ModifyUser(argc, argv)
-int argc;
-char **argv;
+AddNewUser()
{
- int status;
- char *temp_buf, error_buf[BUFSIZ];
- struct qelem * elem, * local;
-
- local = elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
-
- while (local != NULL) {
- char ** info = (char **) local->q_data;
- char ** args = AskUserInfo(info, TRUE);
-
- if ( (status = sms_query("update_user", CountArgs(args),
- args, Scream, NULL)) != 0) {
- com_err(program_name, status, " in ModifyFields");
- if (local->q_forw == NULL)
- temp_buf = "";
- else
- temp_buf = ", Continuing to next user";
- sprintf(error_buf,"User %s not updated due to error%s.",
- info[NAME], temp_buf);
- Put_message(error_buf);
- }
- local = local->q_forw;
- }
- FreeQueue(elem);
+ register int status;
+ char ** args, *info[MAX_ARGS_SIZE];
+
+ args = AskUserInfo(SetUserDefaults(info), FALSE);
+ if ( (status = sms_query("add_user", CountArgs(args),
+ args, Scream, (char *) NULL)) != SMS_SUCCESS)
+ com_err(program_name, status, " in add_user");
+ else
+ Put_message("New user added to database.");
+ FreeInfo(args);
return(DM_NORMAL);
}
-/* Function Name: POType
- * Description: Asks the SMS server if it is of type pop, of
- * of type local. If neither, we assume that it's
- * of type foreign.
- * Arguments: machine - a canonicalized machine name,
- * Returns: the PO Type, one of: pop, local, foreign.
+/* Function Name: GetLoginName
+ * Description: Asks the user for a login name and reserves
+ * it with kerberous.
+ * Arguments: none.
+ * Returns: a malloced login name for the user.
*/
-char *
-POType(machine)
-char *machine;
+static char *
+GetLoginName()
{
- int status;
- char * type;
- struct qelem *top, *elem = NULL;
-
- type = "pop";
- status = sms_query("get_server_locations", 1, &type,
- StoreInfo, &elem);
- if (status && (status != SMS_NO_MATCH)) {
- com_err(program_name, status, (char *) NULL);
- return( (char *) NULL);
- }
+ char name[BUFSIZ];
+
+ Prompt_input("Login name for this user? ", name, BUFSIZ);
+
+ Put_message(
+ "KERBEROS code not added, did not reserve name with kerberos.");
+
+ return(Strsave(name));
+}
+
+
+/* Function Name: ChooseUser
+ * Description: Choose a user from a list and return the uid.
+ * Arguments: top - a queue of user information.
+ * Returns: uid - the malloced uid of the user that was chosen.
+ */
- top = elem = QueueTop(elem);
+static char *
+ChooseUser(elem)
+struct qelem * elem;
+{
while (elem != NULL) {
- char ** info = (char **) elem->q_data;
- if (strcmp (info[1], machine) == 0) {
- FreeQueue(top);
- return( Strsave("POP") );
+ char ** info = (char **) elem->q_data;
+ PrintUserInfo(info);
+ switch(YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) {
+ case TRUE:
+ return(Strsave(info[U_UID]));
+ case FALSE:
+ break;
+ default: /* quit or ^C. */
+ return(NULL);
}
elem = elem->q_forw;
}
- FreeQueue(top);
- return ( Strsave("SMTP") );
+ return(NULL);
}
-/* Function Name: ChangeUserPOBox
- * Description: Changes The P.O. Box for a user.
- * Arguments: argc, argv - the login name of the user in argv[1].
- * Returns: DM_NORMAL.
+/* Function Name: GetUidNumberFromName
+ * Description: Gets the users uid number, from the name.
+ * Arguments: none.
+ * Returns: uid - a malloced string containing the uid.
*/
-/*ARGSUSED*/
-int
-ChangeUserPOBox(argc, argv)
-int argc;
-char **argv;
+static char *
+GetUidNumberFromName()
{
+ char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
register int status;
- struct qelem * poqueue, *local;
- char *type, buf[BUFSIZ], *pohost;
- static char *po[4];
- poqueue = NULL;
+ struct qelem * top = NULL;
+
+ Prompt_input("First Name: ", first, BUFSIZ);
+ Prompt_input("Last Name: ", last, BUFSIZ);
- sprintf(buf,"Current pobox for user %s: \n", argv[1]);
- Put_message(buf);
- status = sms_query("get_pobox", 1, argv + 1, PrintPOBoxes, NULL);
- if (status != SMS_NO_MATCH && status != 0) {
- com_err(program_name, status, "in ChangeUserPOBox.");
- return(DM_NORMAL);
- }
- else if (status == SMS_NO_MATCH)
- Put_message("This user has no P.O. Box.");
+ args[0] = first;
+ args[1] = last;
- if (YesNoQuestion("Shall we use the least loaded Post Office?", TRUE)) {
- po[0] = "pop";
- po[1] = "*";
- if ( status = sms_query ("get_server_host_info", 2, po,
- StoreInfo, (char *) &poqueue) != 0) {
- com_err(program_name, status,
- " in ChangeUserPOBox (get_server_host_info).");
- return(DM_NORMAL);
- }
- local = poqueue;
- while (local != NULL) {
- char ** args = (char **) local->q_data;
- int new_space, old_space = -1 ;
- if ( !isdigit(*args[6]) || !isdigit(*args[7]) )
- Put_message(
- "non-digit value in server_host_info, this is a bug.");
- else {
- new_space = atoi(argv[7]) - atoi(args[6]);
- if ( (new_space < old_space) || (old_space == -1) ) {
- old_space = new_space;
- strcpy(buf, args[1]);
- }
- }
- local = local->q_forw;
- }
- pohost = Strsave(buf);
- FreeQueue(poqueue);
- type = "POP";
- (void) sprintf(buf, "The Post Office %s was chosen.",
- pohost);
- Put_message(buf);
- }
- else if( (Prompt_input("Which Machine for Post Office?",
- buf, BUFSIZ)) ) {
- if ( (pohost = CanonicalizeHostname(buf)) == NULL) {
- Put_message("\nNameserver doesn't know that machine, sorry.");
- return (DM_NORMAL);
- }
- type = POType(pohost);
+ switch (status = sms_query("get_user_by_name", 2, args,
+ StoreInfo, &top)) {
+ case SMS_SUCCESS:
+ break;
+ case SMS_NO_MATCH:
+ Put_message("There is no user in the database with that name.");
+ return(NULL);
+ default:
+ com_err(program_name, status, " in get_user_by_name.");
+ return(NULL);
}
- sprintf(buf, "%s %s's %s %s?", "Are you sure that you want to replace all",
- argv[1], "P.O. Boxes\n with ** ONE ** on the machine", pohost);
-
- if(Confirm(buf)) {
- po[0] = argv[1];
- po[1] = type;
- po[2] = pohost;
- po[3] = po[0];
- if (status = sms_query("set_pobox", 4, po, Scream, NULL) != 0 )
- com_err(program_name, status, " in ChangeUserPOBox");
- } else
- Put_message("Operation Aborted.");
+ top = QueueTop(top);
+ if (QueueCount(top) == 1) /* This is a unique name. */ {
+ char ** info = (char **) top->q_data;
+ Put_message("User ID Number retrieved for the user: ");
+ Put_message("");
+ PrintUserName(info);
+ uid = Strsave(info[U_UID]);
+ FreeQueue(top);
+ return(Strsave(uid));
+ }
- return (DM_NORMAL);
+ Put_message("That name is not unique, choose the user that you want.");
+ uid = ChooseUser(top);
+ FreeQueue(top);
+ return(uid);
}
-/* ------------------------- Top Menu ------------------------- */
-
-/* delete user in delete.c */
-
-/* Function Name: DeleteUserByUid
- * Description: Deletes the user given a uid number.
- * Arguments: argc, argv - uid if user in argv[1].
- * Returns: DM_NORMAL.
+/* Function Name: SetUserPassword
+ * Description: Set the new kerberos password for this user.
+ * Arguments: name - kerberos principle name for this user, (login name).
+ * Returns: none.
*/
-/*ARGSUSED*/
-int
-DeleteUserByUid(argc, argv)
-int argc;
-char **argv;
+static void
+SetUserPassword(name)
+char * name;
{
- int status;
-
- if (Confirm("Are you sure you want to remove this user"))
- if ( (status = sms_query("delete_user_by_uid", 1, argv+1, Scream,
- (char * ) NULL)) != 0)
- com_err(program_name, status, " in DeleteUserByUid");
-
- return(DM_NORMAL);
-}
-
-/* ------------------------- Show Quota Info ------------------------- */
+ name = name; /* make saber happy. */
+ Put_message("Kerberos password not changed, code non-existant.");
+ /* clever message to call account_admin, if this fails. */
+}
-/* Function Name: ShowDefaultQuota
- * Description: This prints out a default quota for the system.
- * Arguments: none
- * Returns: DM_NORMAL.
+/* Function Name: GiveBackLogin
+ * Description: Gives back previously reserved kerberous principle.
+ * Arguments: name - principle to give back.
+ * Returns: void.
*/
-int
-ShowDefaultQuota()
+static void
+GiveBackLogin(name)
+char * name;
{
- int status;
- static char *val[] = {"def_quota"};
-
- if (status = sms_query("get_value", 1, val, Print, (char *) NULL) != 0)
- com_err(program_name, status, " in ShowDefaultQuota");
-
- return (DM_NORMAL);
+ name = name; /* make saber happy. */
+ Put_message("kerberos code not implimented, name not given back.");
+ /* send mail to db maintainer if this fails. */
}
-/* Function Name: ShowUserQuota
- * Description: Shows the quota of a user.
- * Arguments: argc, argv - users login name is argv[1].
- * Returns: DM_NORMAL
+/* Function Name: RegisterUser
+ * Description: This function registers a user.
+ * Arguments: none.
+ * Returns: DM_NORMAL.
*/
-/*ARGSUSED*/
int
-ShowUserQuota(argc, argv)
-int argc;
-char **argv;
+RegisterUser()
{
- struct qelem *elem, *top;
- top = elem = GetUserInfo(QUOTA, argv[1], (char *) NULL);
+ char * args[MAX_ARGS_SIZE];
+ char *login, *fstype = NULL;
+ char temp_buf[BUFSIZ];
+ register int status;
- while (elem != NULL) {
- char ** info = (char **) elem->q_data;
- PrintQuota(info);
- elem = elem->q_forw;
+ Put_message("This function has NO kerberos support, so stange 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] = Strsave(temp_buf);
+ break;
+ case FALSE:
+ if ( (args[0] = GetUidNumberFromName()) == NULL)
+ return(DM_NORMAL);
+ break;
+ default:
+ return(DM_NORMAL);
}
- FreeQueue(top);
- return (DM_NORMAL);
+
+ if ( ((login = args[1] = GetLoginName()) == NULL) ||
+ ( GetFSTypes(&fstype) == SUB_ERROR ) ) {
+ FreeInfo(args); /* This work because the NULL temination is ok. */
+ return(DM_NORMAL);
+ }
+ args[2] = fstype;
+ args[3] = NULL;
+
+ switch (status = sms_query("register_user", CountArgs(args),
+ args, Scream, (char *) NULL)) {
+ case SMS_SUCCESS:
+ sprintf(temp_buf, "User %s successfully registered.", login);
+ Put_message(temp_buf);
+ SetUserPassword(login);
+ break;
+ case SMS_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);
}
-/* Function Name: ChangeDefaultQuota
- * Description: Changes the System Wide default quota.
- * Arguments: argc, argv - New quota in argv[1].
- * Returns: DM_NORMAL.
+/* Function Name: RealUpdateUser
+ * Description: actuall updates the user information.
+ * Arguments: info - all current information for the user fields.
+ * junk - an UNUSED boolean.
+ * Returns: none.
*/
-/*ARGSUSED*/
-int
-ChangeDefaultQuota(argc, argv)
-int argc;
-char *argv[];
+/* ARGSUSED */
+static void
+RealUpdateUser(info, junk)
+char ** info;
+Bool junk;
{
- char buf[BUFSIZ];
- int status;
- static char *newval[] = {
- "update_value", "def_quota", NULL,
- };
-
- sprintf(buf,"%s%s",
- "Are you sure that you want to change the default quota\n",
- "for all new users? (y/n) ");
- if(!Confirm(buf)) {
- newval[2] = argv[1];
- if (status = sms_query("update_value", 3, newval, Scream, NULL) != 0)
- com_err(program_name, status, " in update_value");
+ register int status;
+ char error_buf[BUFSIZ];
+ char ** args = AskUserInfo(info, TRUE);
+
+ if ( (status = sms_query("update_user", CountArgs(args),
+ args, Scream, (char *) NULL)) != SMS_SUCCESS) {
+ com_err(program_name, status, " in ModifyFields");
+ sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
+ Put_message(error_buf);
}
- else
- Put_message("Quota not changed.");
-
- return (DM_NORMAL);
}
-/* ---------------------- User Locker Manipultation -------------------- */
-
-/* Function Name: AddUserLocker
- * Description: Add a new locker for a user.
- * Arguments: arc, argv -
- * argv[1] login name of user.
- * argv[2] server host name.
- * argv[3] Directory on host.
- * argv[4] quota in Kb.
+/* Function Name: UpdateUser
+ * Description: Modify some of the information about a user.
+ * Arguments: argc, argv - login name of the user in argv[1].
* Returns: DM_NORMAL.
*/
-/*ARGSUSED*/
+/* ARGSUSED */
int
-AddUserLocker(argc, argv)
+UpdateUser(argc, argv)
int argc;
char **argv;
{
- int status;
- char *args[4];
+ struct qelem * elem;
- args[0] = argv[1];
- args[2] = argv[3];
- args[3] = argv[4];
-
- args[1] = CanonicalizeHostname(argv[2]);
- if (args[1] == (char *)NULL) {
- Put_message("Could not canonicalize hostname; continuing..");
- args[1] = argv[2];
- }
+ elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
+ QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
- if (status = sms_query("add_locker", 4, args, Scream, NULL) != 0)
- com_err(program_name, status, " in add_user_locker");
-
+ FreeQueue(elem);
return(DM_NORMAL);
}
-/* needs to be fixed - CDP 6/10/88 */
+/* ------------------------- Top Menu ------------------------- */
+
+/* DeleteUser() in delete.c */
-/* Function Name: DeleteUserLocker
- * Description: Deletes a locker - BOOM.
- * Arguments: arc, argv - the name of the locker in argv[1]/
+/* Function Name: DeleteUserByUid
+ * Description: Deletes the user given a uid number.
+ * Arguments: argc, argv - uid if user in argv[1].
* Returns: DM_NORMAL.
+ * NOTES: This just gets the username from the sms server
+ * and performs a DeleteUser().
*/
-/*ARGSUSED*/
int
-DeleteUserLocker(argc, argv)
+DeleteUserByUid(argc, argv)
int argc;
char **argv;
{
int status;
- if (status = sms_query("delete_locker", 1, argv + 1,
- Scream, (char *)NULL) != 0)
- com_err(program_name, status, " in delete_locker");
+ struct qelem *elem = NULL;
+ char ** info;
+
+ if(!ValidName(argv[1]))
+ return(DM_NORMAL);
+
+ if ( (status = sms_query("get_user_by_uid", 1, argv+1, StoreInfo,
+ (char * ) &elem)) != SMS_SUCCESS)
+ com_err(program_name, status, " in get_user_by_uid");
+
+ info = (char **) elem->q_data;
+ argv[1] = info[U_NAME];
+ (void) DeleteUser(argc, argv);
return(DM_NORMAL);
-}
+}
-/* Function Name: ChangeUserQuota
- * Description: This function allows all quotas to be updated for a user.
- * Arguments: arg, argv - the name of the user in argv[1].
- * Returns: DM_NORMAL.
- */
-
-/* ARGSUSED */
-int
-ChangeUserQuota(argc, argv)
-int argc;
-char *argv[];
-{
- int status;
- char error_buf[BUFSIZ];
- struct qelem *elem, *local;
-
- elem = GetUserInfo(QUOTA, argv[1], (char *) NULL);
-
- local = elem;
- while (local != NULL) {
- char **info;
- info = (char **) local->q_data;
- PrintQuota(info);
- GetValueFromUser("New quota (in KB): ", &info[Q_QUOTA]);
-
- if (status = sms_query("update_nfs_quota", 3, info,
- Scream, (char *) NULL) != 0) {
- com_err(program_name, status, " in update_nfs_quota");
- sprintf(error_buf,"Could not perform quota change on %s",
- info[Q_FILESYS]);
- Put_message(error_buf);
- }
- local = local->q_forw;
- }
- FreeQueue(elem);
- return (DM_NORMAL);
-}
+/* ------------------------- Show User Information ------------------------- */
/* Function Name: ShowUserByLogin
* Description: Shows user information given a login name.
struct qelem *top, *elem;
elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL);
- while (elem != NULL) {
- PrintUserInfo( (char **) elem->q_data, FALSE);
- elem = elem->q_forw;
- }
+ Loop(elem, PrintUserInfo);
FreeQueue(top);
return (DM_NORMAL);
int argc;
char *argv[];
{
- struct qelem *top, *elem;
+ struct qelem *top;
char buf;
- elem = top = GetUserInfo(BY_NAME, argv[1], argv[2]);
+ top = GetUserInfo(BY_NAME, argv[1], argv[2]);
- if (!PromptWithDefault("Print full information, or just the names (F/N)?",
- &buf, 1, "F"))
+ if (top == NULL) /* if there was an error then return. */
return(DM_NORMAL);
- while (elem != NULL) {
- switch(buf) {
- case 'F':
- case 'f':
- PrintUserInfo( (char **) elem->q_data, FALSE);
- break;
- case 'N':
- case 'n':
- PrintUserInfo( (char **) elem->q_data, TRUE);
- break;
- }
- elem = elem->q_forw;
- }
+ if (!PromptWithDefault("Print full information, or just the names (f/n)?",
+ &buf, 1, "f"))
+ return(DM_NORMAL);
+ switch(buf) {
+ case 'F':
+ case 'f':
+ Loop(top, PrintUserInfo);
+ break;
+ case 'N':
+ case 'n':
+ Loop(top, PrintUserName);
+ break;
+ }
+
FreeQueue(top);
return (DM_NORMAL);
}
int argc;
char **argv;
{
- struct qelem *top, *elem;
+ struct qelem *top;
- elem = top = GetUserInfo(CLASS, argv[1], (char *) NULL);
-
- while (elem != NULL) {
- PrintUserInfo( (char **) elem->q_data, TRUE);
- elem = elem->q_forw;
- }
+ top = GetUserInfo(CLASS, argv[1], (char *) NULL);
+ Loop(top, PrintUserName);
FreeQueue(top);
return (DM_NORMAL);
}
-
-/* Function Name: PrintQuota
- * Description: Prints a users quota information.
- * Arguments: info - a pointer to the quota information:
- * Returns: none.
- */
-
-static void
-PrintQuota(info)
-char ** info;
-{
- char buf[BUFSIZ];
-
- sprintf(buf, "Machine: %s\t\tDirectory: %s\t\tQuota: %s",
- info[Q_MACHINE], info[Q_DIRECTORY], info[Q_QUOTA]);
- Put_message(buf);
-}
-
-/* Function Name: PrintPOBoxes
- * Description: Yet another specialized print function.
- * Arguments: argc, argv -
- * argv[0] - login name.
- * argv[1] - type.
- * argv[2] - machine.
- * argv[3] - box name.
- * junk. - NOT USED
- * Returns: SMS_CONT
- */
-
-/* ARGSUSED */
-static int
-PrintPOBoxes(argc, argv, junk)
-int argc;
-char **argv;
-char * junk;
-{
- char buf[BUFSIZ];
- /* no newline 'cause Put_message adds one */
-
- (void) sprintf(buf, "Address: %s@%s\t\tType: %s", argv[PO_BOX],
- argv[PO_MACHINE], argv[PO_TYPE]);
- (void) Put_message(buf);
-
- return (SMS_CONT);
-}
-
-/* Function Name: PrintUserInfo
- * Description: Prints Information about a user.
- * Arguments: info - an argument list with the user information
- * in it.
- * name_only - if TRUE then print only the users name.
- * Returns: none
- */
-
-static void
-PrintUserInfo(info, name_only)
-char ** info;
-Bool name_only;
-{
- char buf[BUFSIZ];
-
- if (name_only) {
- sprintf(buf, "%s, %s %s", info[U_LAST],
- info[U_FIRST], info[U_MIDDLE]);
- sprintf(buf, "%-40s/tUser Name: %s", buf, info[U_NAME]);
- Put_message(buf);
- }
- else {
- (void) sprintf(buf,
- "Login name: %-10s/tUser id: %-10s\tLogin shell %s",
- info[U_NAME], info[U_UID], info[U_SHELL]);
- (void) Put_message(buf);
- (void) sprintf(buf, "Full name: %s %s %s\tClass: %s",
- info[U_FIRST], info[U_MIDDLE],
- info[U_LAST], info[U_CLASS]);
- (void) Put_message(buf);
- (void) sprintf(buf,
- "Account status: %s\tEncrypted MIT ID number: %s",
- atoi(info[U_STATE]) ? "active" : "inactive",
- info[U_MITID]);
- (void) Put_message(buf);
- (void) sprintf(buf, "Last Modification by %s at %s with %s.",
- info[U_MODBY], info[U_MODTIME], info[U_MODWITH]);
- (void) Put_message(buf);
- }
-}
-
/*
* Local Variables:
* mode: c
#include "infodefs.h"
#include <netdb.h> /* for gethostbyname. */
-/* #include <ctype.h> */
-/* #include <varargs.h> */
-/* #include <sys/types.h> */
/* Function Name: FreeInfo
* Description: Frees all elements of a NULL terminated arrary of char*'s
* Arguments: prompt - prompt for user.
* pointer - pointer to default value, will be returned
* as new value.
- * Returns: none.
+ * Returns: SUB_ERROR if break hit (^C).
*/
-void
+int
GetValueFromUser(prompt, pointer)
char * prompt, ** pointer;
{
char buf[BUFSIZ];
- PromptWithDefault(prompt, buf, BUFSIZ, *pointer);
+ if (PromptWithDefault(prompt, buf, BUFSIZ, *pointer) == -1)
+ return(FALSE);
+
if (*pointer != NULL)
free(*pointer);
*pointer = Strsave(buf);
+ return(TRUE);
+}
+
+/* Function Name: GetYesNoValueFromUser
+ * Description: This function gets a value from a user for the field
+ * specified.
+ * Arguments: prompt - prompt for user.
+ * pointer - pointer to default value, will be returned
+ * as new value.
+ * Returns: SUB_ERROR if break hit (^C).
+ */
+
+int
+GetYesNoValueFromUser(prompt, pointer)
+char * prompt, ** pointer;
+{
+ char user_prompt[BUFSIZ];
+ Bool default_val;
+
+ if ( strcmp (*pointer, DEFAULT_YES) == 0 )
+ default_val = TRUE;
+ else
+ default_val = FALSE;
+
+ sprintf(user_prompt, "%s (y/n)", prompt);
+
+ switch (YesNoQuestion(user_prompt, default_val)) {
+ case TRUE:
+ if (*pointer != NULL)
+ free(*pointer);
+ *pointer = Strsave("1");
+ break;
+ case FALSE:
+ if (*pointer != NULL)
+ free(*pointer);
+ *pointer = Strsave("0");
+ break;
+ case -1:
+ default:
+ return(FALSE);
+ }
+ return(TRUE);
+}
+
+/* Function Name: GetFSVal
+ * Description: asks about a specific filesystem value.
+ * Arguments: name - string for this type of filesystem.
+ * mask - mask for this type of filesystem.
+ * current - current filesystem state. (for defaults).
+ * new - new filesystem state.
+ * Returns: TRUE if successful.
+ */
+
+static Bool
+GetFSVal(name, mask, current, new)
+char * name;
+int mask, current, *new;
+{
+ char temp_buf[BUFSIZ];
+ sprintf(temp_buf, "Is this a %s filsystem", name);
+ switch (YesNoQuestion(temp_buf, ( (mask & current) == mask) )) {
+ case TRUE:
+ *new |= mask;
+ break;
+ case FALSE:
+ break; /* zero by default. */
+ default:
+ return(FALSE);
+ }
+ return(TRUE);
+}
+
+/* Function Name: GetFSTypes
+ * Description: Allows user to specify filsystem types.
+ * Arguments: current - current value of filsystem, freed here.
+ * Returns: SUB_ERROR on ^C.
+ */
+
+int
+GetFSTypes(current)
+char ** current;
+{
+ int c_value, new_val = 0; /* current value of filesys type (int). */
+ char ret_value[BUFSIZ];
+
+ if (*current == NULL)
+ c_value = 0;
+ else
+ c_value = atoi(*current);
+
+ if (GetFSVal("student", SMS_FS_STUDENT, c_value, &new_val) == FALSE)
+ return(SUB_ERROR);
+ if (GetFSVal("faculty", SMS_FS_FACULTY, c_value, &new_val) == FALSE)
+ return(SUB_ERROR);
+ if (GetFSVal("staff", SMS_FS_STAFF, c_value, &new_val) == FALSE)
+ return(SUB_ERROR);
+ if (GetFSVal("miscellaneous", SMS_FS_MISC, c_value, &new_val) == FALSE)
+ return(SUB_ERROR);
+
+ FreeAndClear(current, TRUE);
+ sprintf(ret_value, "%d", new_val);
+ *current = Strsave(ret_value);
+ return(SUB_NORMAL);
}
/* Function Name: CanonicalizeHostname
#define NAME 0
-/* get_acl_use */
+/* get_ace_use */
-#define ACL_TYPE 0
-#define ACL_NAME 1
-#define ACL_END 2
+#define ACE_TYPE 0
+#define ACE_NAME 1
+#define ACE_END 2
/* alias queries. */
-#define ALIAS_NAME NAME
+#define ALIAS_NAME 0
#define ALIAS_TYPE 1
#define ALIAS_TRANS 2
#define ALIAS_END 3
/* Cluster information queries */
-#define C_NAME NAME
+#define C_NAME 0
#define C_DESCRIPT 1
#define C_LOCATION 2
#define C_MODTIME 3
/* Cluster Data information queries */
-#define CD_NAME NAME
+#define CD_NAME 0
#define CD_LABEL 1
#define CD_DATA 2
#define CD_END 3
/* Filesys queries (attachmaint) */
-#define FS_NAME NAME
+#define FS_NAME 0
#define FS_TYPE 1
#define FS_MACHINE 2
#define FS_PACK 3
/* Get List Of Member queries. */
-#define GLOM_NAME NAME
+#define GLOM_NAME 0
#define GLOM_ACTIVE 1
#define GLOM_PUBLIC 2
#define GLOM_HIDDEN 3
/* General List information Queries. */
-#define L_NAME NAME
+#define L_NAME 0
#define L_ACTIVE 1
#define L_PUBLIC 2
#define L_HIDDEN 3
#define L_MAILLIST 4
#define L_GROUP 5
#define L_GID 6
-#define L_ACL_TYPE 7
-#define L_ACL_NAME 8
+#define L_ACE_TYPE 7
+#define L_ACE_NAME 8
#define L_DESC 9
#define L_MODTIME 10
#define L_MODBY 11
/* Machine information queries */
-#define M_NAME NAME
+#define M_NAME 0
#define M_TYPE 1
#define M_MODTIME 2
#define M_MODBY 3
/* NFS phys. queries. */
-#define NFS_NAME NAME
+#define NFS_NAME 0
#define NFS_DIR 1
#define NFS_DEVICE 2
#define NFS_STATUS 3
/* PO box infomarion queries */
-#define PO_NAME NAME
+#define PO_NAME 0
#define PO_TYPE 1
-#define PO_MACHINE 2
-#define PO_BOX 3
-#define PO_END 4
+#define PO_BOX 2
+#define PO_END 3
/* Quota queries */
/* User Information queries */
-#define U_NAME NAME
-#define U_NEWNAME 1
-#define U_UID 2
-#define U_SHELL 3
-#define U_LAST 4
-#define U_FIRST 5
-#define U_MIDDLE 6
-#define U_STATE 7
-#define U_MITID 8
-#define U_CLASS 9
-#define U_MODTIME 10
-#define U_MODBY 11
-#define U_MODWITH 12
-#define U_END 13
+#define U_NAME 0
+#define U_UID 1
+#define U_SHELL 2
+#define U_LAST 3
+#define U_FIRST 4
+#define U_MIDDLE 5
+#define U_STATE 6
+#define U_MITID 7
+#define U_CLASS 8
+#define U_MODTIME 9
+#define U_MODBY 10
+#define U_MODWITH 11
+#define U_END 12
#endif _infodefs_ /* Do not add anything after this line. */