#endif not lint
/*
- * Talk to the SMS database to change a person's GECOS information.
+ * Talk to the MOIRA database to change a person's GECOS information.
*
* chfn with no modifiers changes the information of the user who is
* running the program.
#include <sys/types.h>
#include <stdio.h>
-#include <strings.h>
-#include <ctype.h>
+#include <string.h>
#include <sys/file.h>
#include <krb.h>
#include <ctype.h>
#include <errno.h>
-/* SMS includes */
-#include <sms.h>
-#include <sms_app.h>
+/* MOIRA includes */
+#include <moira.h>
+#include <moira_site.h>
#include "mit-copyright.h"
char *whoami;
int k_errno;
char *whoami;
- if ((whoami = rindex(argv[0], '/')) == NULL)
+ if ((whoami = strrchr(argv[0], '/')) == NULL)
whoami = argv[0];
else
whoami++;
leave(status)
int status;
- /* This should be called rather than exit once connection to sms server
+ /* This should be called rather than exit once connection to moira server
has been established. */
{
- sms_disconnect();
+ mr_disconnect();
exit(status);
}
scream()
{
- com_err(whoami, 0, "Unexpected return value from SMS -- programmer botch");
+ com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch");
leave(1);
}
char *uname;
{
int status; /* general purpose exit status */
- int q_argc; /* argc for sms_query */
- char *q_argv[F_END]; /* argv for sms_query */
+ int q_argc; /* argc for mr_query */
+ char *q_argv[F_END]; /* argv for mr_query */
+ char *motd; /* for MR server status */
int i;
int get_user_info();
/* Try each query. If we ever fail, print error message and exit. */
- status = sms_connect(SMS_SERVER);
+ status = mr_connect(NULL);
if (status) {
- com_err(whoami, status, " while connecting to SMS");
+ com_err(whoami, status, "while connecting to Moira");
exit(1);
}
- status = sms_auth("chfn"); /* Don't use argv[0] - too easy to fake */
+ status = mr_motd(&motd);
+ if (status) {
+ com_err(whoami, status, "unable to check server status");
+ leave(1);
+ }
+ if (motd) {
+ fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
+ leave(1);
+ }
+
+ status = mr_auth("chfn"); /* Don't use argv[0] - too easy to fake */
if (status) {
com_err(whoami, status,
- " while authenticating -- run \"kinit\" and try again.");
+ "while authenticating -- run \"kinit\" and try again.");
leave(1);
}
q_argv[i] = "junk";
q_argc = F_MODTIME; /* one more than the last updatable field */
- if (status = sms_access("update_finger_by_login", q_argc, q_argv)) {
+ if (status = mr_access("update_finger_by_login", q_argc, q_argv)) {
com_err(whoami, status, "; finger\ninformation not changed.");
leave(2);
}
q_argv[NAME] = uname;
q_argc = NAME + 1;
- if (status = sms_query("get_finger_by_login", q_argc, q_argv,
+ if (status = mr_query("get_finger_by_login", q_argc, q_argv,
get_user_info, (char *) &old_info))
{
- com_err(whoami, status, " while getting user information.");
+ com_err(whoami, status, "while getting user information.");
leave(2);
}
q_argv[F_MIT_AFFIL] = new_info.mit_year;
q_argc = F_MODTIME; /* First non-update query argument */
- if (status = sms_query("update_finger_by_login", q_argc, q_argv,
+ if (status = mr_query("update_finger_by_login", q_argc, q_argv,
scream, (char *)NULL))
{
- com_err(whoami, status, " while updating finger information.");
+ com_err(whoami, status, "while updating finger information.");
leave(1);
}
/* Only pay attention to the first match since login names are
unique in the database. */
- return(SMS_ABORT);
+ return(MR_ABORT);
}
char *ask(question, def_val, phone_num)
char *def_val;
int phone_num; /* True if this must contain only digits */
{
- char buf[BUFSIZ];
+ static char buf[BUFSIZ];
int ok = FALSE;
char *result;
int i;
{
ok = TRUE;
printf("%s [%s]: ", question, def_val);
- (void) fgets(buf, sizeof(buf), stdin);
+ if (fgets(buf, sizeof(buf), stdin) == NULL)
+ leave(0);
buf[strlen(buf) - 1] = NULL;
if (strlen(buf) == 0)
result = def_val;
}
if (phone_num && ok) {
- for (i = 0; i < strlen(buf); i++) {
- if (!isdigit(buf[i]) && (buf[i] != '-')) {
+ for (i = 0; i < strlen(result); i++) {
+ if (!isdigit(result[i]) && (result[i] != '-')) {
printf("Phone numbers can contain only digits.\n");
ok = FALSE;
break;
}
- if (buf[i] == '-')
+ if (result[i] == '-')
dashes = TRUE;
}
}
}
/* Remove dashes if necessary */
- if (dashes) {
+ if (dashes && result == buf) {
char *tmp1, *tmp2;
- result = strsave(buf);
- tmp1 = (char *)buf;
- tmp2 = result;
+ tmp1 = tmp2 = (char *)buf;
do {
if (*(tmp1) != '-')
*(tmp2++) = *(tmp1);
GETINFO("Office address (Exs: E40-342 or 2-108)",
office_address, FALSE);
GETINFO("Office phone (Ex: 3-1300)", office_phone, TRUE);
- GETINFO("MIT department (Exs: 9, Biology, Information Services",
+ GETINFO("MIT department (Exs: 9, Biology, Information Services)",
mit_department, FALSE);
GETINFO("MIT year (Exs: 1989, '91, Faculty, Grad)", mit_year, FALSE);
}