static char rcsid_module_c[] = "$Header$";
#endif lint
-/* This is the file utils.c for the SMS Client, which allows a nieve
- * user to quickly and easily maintain most parts of the SMS database.
+/* This is the file utils.c for the MOIRA Client, which allows a nieve
+ * user to quickly and easily maintain most parts of the MOIRA database.
* It Contains: Many useful utility functions.
*
* Created: 4/25/88
*/
#include <stdio.h>
-#include <strings.h>
-#include <sms.h>
+#include <string.h>
+#include <moira.h>
+#include <moira_site.h>
#include <menu.h>
#include <ctype.h>
#include "defs.h"
#include "f_defs.h"
#include "globals.h"
-#include "infodefs.h"
-
#include <netdb.h> /* for gethostbyname. */
+#include <sys/types.h>
+#include <netinet/in.h>
+
/* Function Name: AddQueue
* Description: Adds an element to a queue
(elem->q_back)->q_forw = elem->q_forw;
}
+
+/* CopyInfo: allocates memory for a copy of a NULL terminated array of
+ * strings <and returns a pointer to the copy.
+ */
+
+char **CopyInfo(info)
+char **info;
+{
+ char **ret;
+ int i;
+
+ ret = (char **) malloc(sizeof(char *) * (CountArgs(info) + 1));
+ if (ret == NULL)
+ return(ret);
+ for (i = 0; info[i]; i++)
+ ret[i] = Strsave(info[i]);
+ ret[i] = NULL;
+ return(ret);
+}
+
+
/* Function Name: FreeInfo
* Description: Frees all elements of a NULL terminated arrary of char*'s
* Arguments: info - array who's elements we are to free.
}
/* Function Name: StoreInfo
- * Description: Stores information from an sms query into a queue.
+ * Description: Stores information from an moira query into a queue.
* Arguments: argc, argv, - information returned from the query returned
* in argv.
* data - the previous element on the queue, this data will be
* If NULL then a new queue will be created. This value
* is updated to the current element at the end off the
* call.
- * Returns: SMS_CONT, or SMS_ABORT if it has problems.
+ * Returns: MR_CONT, or MR_ABORT if it has problems.
*/
int
Put_message("Could Not allocate more memory.");
FreeQueue(*old_elem);
*old_elem = (struct qelem *) NULL;
- return(SMS_ABORT);
+ return(MR_ABORT);
}
for (count = 0; count < argc; count++)
AddQueue(new_elem, *old_elem);
*old_elem = new_elem;
- return(SMS_CONT);
+ return(MR_CONT);
}
/* Function Name: CountArgs
Scream()
{
com_err(program_name, 0,
- "\nAn SMS update returned a value -- programmer botch\n");
- sms_disconnect();
+ "\nA Moira update returned a value -- programmer botch\n");
+ mr_disconnect();
exit(1);
+ /*NOTREACHED*/
+ return(-1);
}
/* Function Name: PromptWithDefault
* Arguments: prompt - the prompt string.
* buf, buflen - buffer to be returned and its MAX size?
* default value for the answer.
- * Returns: the value returned by prompt_input.
+ * Returns: zero on failure
*/
int
char tmp[BUFSIZ];
int ans;
+ if (parsed_argc > 0) {
+ parsed_argc--;
+ strncpy(buf, parsed_argv[0], buflen);
+ sprintf(tmp, "%s: %s", prompt, buf);
+ Put_message(tmp);
+ parsed_argv++;
+ return(1);
+ }
+
(void) sprintf(tmp, "%s [%s]: ", prompt, def ? def : "");
ans = Prompt_input(tmp, buf, buflen);
- if (ans == 0) {
- if (YesNoQuestion("Are you sure you want to exit", 1)) {
- Cleanup_menu();
- exit(0);
- }
- Put_message("Continuing input...");
- return(PromptWithDefault(prompt, buf, buflen, def));
- }
if (IS_EMPTY(buf))
(void) strcpy(buf, def);
else if (!strcmp(buf, "\"\""))
{
if (IS_EMPTY(s))
Put_message("Please use a non-empty name.");
- else if (index(s, ' '))
+ else if (strchr(s, ' '))
Put_message("You cannot use space (' ') in this name.");
- else if (index(s, WILDCARD))
+ else if (strchr(s, '*') || strchr(s, '?') || strchr(s, '['))
Put_message("Wildcards not accepted here.");
else
return TRUE;
/* Function Name: NullFunc
* Description: dummy callback routine
* Arguments: none
- * Returns: SMS_CONT
+ * Returns: MR_CONT
*/
int
NullFunc()
{
- return(SMS_CONT);
+ return(MR_CONT);
}
/* Function Name: SlipInNewName
register int i;
/* This also pushes the NULL down. */
- for (i = CountArgs(info); i > 1; i--) {
- info[i] = info[i-1];
+ for (i = CountArgs(info); i > 0; i--) {
+ info[i+1] = info[i];
}
info[1] = name; /* now slip in the name. */
}
{
char buf[BUFSIZ];
- if (PromptWithDefault(prompt, buf, BUFSIZ, *pointer) == -1)
+ if (PromptWithDefault(prompt, buf, BUFSIZ, *pointer) == 0)
return(SUB_ERROR);
/*
* a difference that makes no difference, IS no difference.
*/
- if (strcmp(buf, *pointer) != 0) {
- if (*pointer != NULL)
+ if (*pointer != NULL) {
+ if (strcmp(buf, *pointer) != 0) {
free(*pointer);
- *pointer = Strsave(buf);
+ *pointer = Strsave(buf);
+ }
}
return(SUB_NORMAL);
}
*/
int
-GetFSTypes(current)
+GetFSTypes(current, options)
char ** current;
+int options;
{
int c_value, new_val = 0; /* current value of filesys type (int). */
char ret_value[BUFSIZ];
else
c_value = atoi(*current);
- if (GetFSVal("student", SMS_FS_STUDENT, c_value, &new_val) == FALSE)
+ if (GetFSVal("student", MR_FS_STUDENT, c_value, &new_val) == FALSE)
return(SUB_ERROR);
- if (GetFSVal("faculty", SMS_FS_FACULTY, c_value, &new_val) == FALSE)
+ if (GetFSVal("faculty", MR_FS_FACULTY, c_value, &new_val) == FALSE)
return(SUB_ERROR);
- if (GetFSVal("staff", SMS_FS_STAFF, c_value, &new_val) == FALSE)
+ if (GetFSVal("staff", MR_FS_STAFF, c_value, &new_val) == FALSE)
return(SUB_ERROR);
- if (GetFSVal("miscellaneous", SMS_FS_MISC, c_value, &new_val) == FALSE)
+ if (GetFSVal("miscellaneous", MR_FS_MISC, c_value, &new_val) == FALSE)
return(SUB_ERROR);
+ if (options) {
+ if (GetFSVal("Group Quotas", MR_FS_GROUPQUOTA, c_value, &new_val) ==
+ FALSE)
+ return(SUB_ERROR);
+ }
FreeAndClear(current, TRUE);
sprintf(ret_value, "%d", new_val);
return(SUB_NORMAL);
}
-/* Function Name: CanonicalizeHostname
- * Description: This function takes a machine name and canonicalize's it.
- * Arguments: machine - name of the machine to work on.
- * Returns: new name or NULL if nameserver returns error
- */
-
-char *
-CanonicalizeHostname(machine)
-char *machine;
-{
- struct hostent *hostinfo;
-
- hostinfo = gethostbyname(machine);
-/* If this fails then we just return what we were passed. */
- if (hostinfo != (struct hostent *) NULL)
- machine = hostinfo->h_name;
- return (machine);
-}
-
/* Function Name: Strsave
* Description: save a string.
* Arguments: string - the string to save.
return (strcpy(newstr, str));
}
+
+/* atot: convert ASCII integer unix time into human readable date string */
+
+char *atot(itime)
+char *itime;
+{
+ int time;
+ char *ct, *ctime();
+
+ time = atoi(itime);
+ ct = ctime(&time);
+ ct[24] = 0;
+ return(&ct[4]);
+}
+
+
/* Function Name: Print
* Description: prints out all the arguments on a single line.
- * Arguments: argc, argv - the standard SMS arguments.
+ * Arguments: argc, argv - the standard MR arguments.
* callback - the callback function - NOT USED.
- * Returns: SMS_CONT
+ * Returns: MR_CONT
*/
/* ARGSUSED */
(void) sprintf(buf,"%s %s",buf,argv[i]);
(void) Put_message(buf);
- return (SMS_CONT);
+ return (MR_CONT);
}
/* Function Name: PrintByType
* Description: This function prints all members of the type specified
* by the callback arg, unless the callback is NULL, in which
* case it prints all members.
- * Arguments: argc, argc - normal arguments for sms_callback function.
+ * Arguments: argc, argc - normal arguments for mr_callback function.
* callback - either a type of member or NULL.
- * Returns: SMS_CONT or SMS_QUIT.
+ * Returns: MR_CONT or MR_QUIT.
*/
/*ARGSUSED*/
return( Print(argc, argv, callback) );
if (strcmp(argv[0], callback) == 0)
return( Print(argc, argv, callback) );
- return(SMS_CONT);
+ return(MR_CONT);
}
/* Function Name: PrintHelp
Bool one_item;
char temp_buf[BUFSIZ], *name;
+ elem = QueueTop(elem);
one_item = (QueueCount(elem) == 1);
while (elem != NULL) {
char **info = (char **) elem->q_data;
argv[1] = "TYPE";
argv[2] = "*";
elem = NULL;
- if (stat = do_sms_query("get_alias", 3, argv, StoreInfo, (char *)&elem)) {
+ if (stat = do_mr_query("get_alias", 3, argv, StoreInfo, (char *)&elem)) {
com_err(program_name, stat, " in GetTypeValues");
return(NULL);
}
}
elem = (struct qelem *) malloc(sizeof(struct qelem));
ce = (struct cache_elem *) malloc(sizeof(struct cache_elem));
- ce->cache_name = tname;
+ ce->cache_name = strsave(tname);
ce->cache_data = QueueTop(oelem);
elem->q_data = (char *)ce;
AddQueue(elem, cache);
/* Function Name: GetTypeFromUser
* Description: gets a typed value from the user
* Arguments: prompt string, type name, buffer pointer
- * Returns:
+ * Returns: SUB_ERROR if ^C, SUB_NORMAL otherwise
*/
-GetTypeFromUser(prompt, tname, pointer)
+int GetTypeFromUser(prompt, tname, pointer)
char *prompt;
char *tname;
char **pointer;
strcat(buffer, ")");
if (strlen(buffer) > 64)
sprintf(buffer, "%s (? for help)", prompt);
- GetValueFromUser(buffer, pointer);
+ if (GetValueFromUser(buffer, pointer) == SUB_ERROR)
+ return(SUB_ERROR);
if (**pointer == '?') {
sprintf(buffer, "Type %s is one of:", tname);
Put_message(buffer);
return(GetTypeFromUser(prompt, tname, pointer));
}
for (elem = GetTypeValues(tname); elem; elem = elem->q_forw) {
- if (!cistrcmp(elem->q_data, *pointer))
+ if (!strcasecmp(elem->q_data, *pointer)) {
+ strcpy(*pointer, elem->q_data);
return(SUB_NORMAL);
+ }
}
sprintf(buffer, "\"%s\" is not a legal value for %s. Use one of:",
*pointer, tname);
}
sprintf(buffer, "Are you sure you want \"%s\" to be a legal %s",
*pointer, tname);
- if (YesNoQuestion("Do you want this to be a new legal value", 0) &&
- YesNoQuestion(buffer, 0)) {
+ if (YesNoQuestion("Do you want this to be a new legal value", 0) == TRUE &&
+ YesNoQuestion(buffer, 0) == TRUE) {
argv[0] = tname;
argv[1] = "TYPE";
argv[2] = *pointer;
- for (p = argv[2]; *p; p++)
+ /* don't uppercase access flags. Do uppercase everything else */
+ if (strncmp(tname, "fs_access", 9))
+ for (p = argv[2]; *p; p++)
if (islower(*p))
- *p = toupper(*p);
- if (stat = do_sms_query("add_alias", 3, argv, Scream, NULL)) {
+ *p = toupper(*p);
+ if (stat = do_mr_query("add_alias", 3, argv, Scream, NULL)) {
com_err(program_name, stat, " in add_alias");
} else {
elem = (struct qelem *) malloc(sizeof(struct qelem));
}
-do_sms_query(name, argc, argv, proc, hint)
+/* Function Name: GetAddressFromUser
+ * Description: gets an IP address from the user
+ * Arguments: prompt string, buffer pointer
+ * buffer contains default value as long int
+ * Returns: SUB_ERROR if ^C, SUB_NORMAL otherwise
+ */
+
+int GetAddressFromUser(prompt, pointer)
+char *prompt;
+char **pointer;
+{
+ char *value, buf[256];
+ struct in_addr addr;
+ int ret;
+
+ addr.s_addr = htonl(atoi(*pointer));
+ value = strsave(inet_ntoa(addr));
+ ret = GetValueFromUser(prompt, &value);
+ if (ret == SUB_ERROR) return(SUB_ERROR);
+ addr.s_addr = inet_addr(value);
+ free(pointer);
+ sprintf(buf, "%d", ntohl(addr.s_addr));
+ *pointer = strsave(buf);
+ return(SUB_NORMAL);
+}
+
+
+do_mr_query(name, argc, argv, proc, hint)
char *name;
int argc;
char **argv;
char *hint;
{
int status;
- extern char *whoami;
+ extern char *whoami, *moira_server;
- status = sms_query(name, argc, argv, proc, hint);
- if (status != SMS_ABORTED && status != SMS_NOT_CONNECTED)
+ refresh_screen();
+ status = mr_query(name, argc, argv, proc, hint);
+ if (status != MR_ABORTED && status != MR_NOT_CONNECTED)
return(status);
- status = sms_connect(SMS_SERVER);
+ status = mr_connect(moira_server);
if (status) {
- com_err(whoami, status, " while re-connecting to server");
- return(SMS_ABORTED);
+ com_err(whoami, status, " while re-connecting to server %s",
+ moira_server);
+ return(MR_ABORTED);
}
- status = sms_auth(whoami);
+ status = mr_auth(whoami);
if (status) {
- com_err(whoami, status, " while re-authenticating to server");
- sms_disconnect();
- return(SMS_ABORTED);
+ com_err(whoami, status, " while re-authenticating to server %s",
+ moira_server);
+ mr_disconnect();
+ return(MR_ABORTED);
}
- status = sms_query(name, argc, argv, proc, hint);
+ status = mr_query(name, argc, argv, proc, hint);
return(status);
}