2 * Copyright 1988 by the Massachusetts Institute of Technology. For copying
3 * and distribution information, see the file "mit-copyright.h".
12 static char *rcsid_chfn_c = "$Header$";
16 * Talk to the SMS database to change a person's GECOS information.
18 * chfn with no modifiers changes the information of the user who is
19 * running the program.
21 * If a commandline argument is given, it is taken to be the username
22 * of the user whose information is to be changed.
29 #include <sys/types.h>
41 #include "mit-copyright.h"
45 extern char *krb_err_txt[];
67 if ((whoami = rindex(argv[0], '/')) == NULL)
80 /* Do it right; get name from kerberos ticket file rather than
83 if (k_errno = tf_init(TKT_FILE, R_TKT_FIL)) {
84 fprintf(stderr, "%s: %s\n", whoami, krb_err_txt[k_errno]);
88 if (k_errno = tf_get_pname(pname)) {
89 fprintf(stderr, "%s: %s\n", whoami, krb_err_txt[k_errno]);
101 /* This should be called rather than exit once connection to sms server
102 has been established. */
110 com_err(whoami, 0, "Unexpected return value from SMS -- programmer botch");
117 int status; /* general purpose exit status */
118 int q_argc; /* argc for sms_query */
119 char *q_argv[F_END]; /* argv for sms_query */
125 struct finger_info old_info;
126 struct finger_info new_info;
128 /* Try each query. If we ever fail, print error message and exit. */
130 status = sms_connect(SMS_SERVER);
132 com_err(whoami, status, " while connecting to SMS");
136 status = sms_auth("chfn"); /* Don't use argv[0] - too easy to fake */
138 com_err(whoami, status,
139 " while authenticating -- run \"kinit\" and try again.");
143 /* First, do an access check. */
145 q_argv[F_NAME] = uname;
146 for (i = F_NAME + 1; i < F_MODTIME; i++)
148 q_argc = F_MODTIME; /* one more than the last updatable field */
150 if (status = sms_access("update_finger_by_login", q_argc, q_argv)) {
151 com_err(whoami, status, "; finger\ninformation not changed.");
155 printf("Changing finger information for %s.\n", uname);
157 /* Get information */
159 q_argv[NAME] = uname;
161 if (status = sms_query("get_finger_by_login", q_argc, q_argv,
162 get_user_info, (char *) &old_info))
164 com_err(whoami, status, " while getting user information.");
168 /* Get the new information from the user */
170 get_new_info(&old_info, &new_info);
174 printf("Changing finger information...\n");
176 q_argv[F_NAME] = uname;
177 q_argv[F_FULLNAME] = new_info.fullname;
178 q_argv[F_NICKNAME] = new_info.nickname;
179 q_argv[F_HOME_ADDR] = new_info.home_address;
180 q_argv[F_HOME_PHONE] = new_info.home_phone;
181 q_argv[F_OFFICE_ADDR] = new_info.office_address;
182 q_argv[F_OFFICE_PHONE] = new_info.office_phone;
183 q_argv[F_MIT_DEPT] = new_info.mit_department;
184 q_argv[F_MIT_AFFIL] = new_info.mit_year;
185 q_argc = F_MODTIME; /* First non-update query argument */
187 if (status = sms_query("update_finger_by_login", q_argc, q_argv,
188 scream, (char *)NULL))
190 com_err(whoami, status, " while updating finger information.");
194 printf("Finger information updated succesfully.\n");
199 get_user_info(argc, argv, message)
204 struct finger_info *old_info = (struct finger_info *) message;
207 fprintf(stderr, "Some internal error occurred; try again.\n");
211 printf("Info last changed on %s by user %s with %s.\n",
212 argv[F_MODTIME], argv[F_MODBY], argv[F_MODWITH]);
214 old_info->fullname = strsave(argv[F_FULLNAME]);
215 old_info->nickname = strsave(argv[F_NICKNAME]);
216 old_info->home_address = strsave(argv[F_HOME_ADDR]);
217 old_info->home_phone = strsave(argv[F_HOME_PHONE]);
218 old_info->office_address = strsave(argv[F_OFFICE_ADDR]);
219 old_info->office_phone = strsave(argv[F_OFFICE_PHONE]);
220 old_info->mit_department = strsave(argv[F_MIT_DEPT]);
221 old_info->mit_year = strsave(argv[F_MIT_AFFIL]);
223 /* Only pay attention to the first match since login names are
224 unique in the database. */
228 char *ask(question, def_val, phone_num)
231 int phone_num; /* True if this must contain only digits */
233 static char buf[BUFSIZ];
244 printf("%s [%s]: ", question, def_val);
245 if (fgets(buf, sizeof(buf), stdin) == NULL)
247 buf[strlen(buf) - 1] = NULL;
248 if (strlen(buf) == 0)
250 else if (strcasecmp(buf, BLANK) == NULL)
255 for (i = 0; i < strlen(buf); i++)
260 printf("'\"' is not allowed.\n");
264 printf("',' is not allowed.\n");
268 printf("':' is not allowed.\n");
272 if (iscntrl(buf[i])) {
273 printf("Control characters are not allowed.\n");
282 if (phone_num && ok) {
283 for (i = 0; i < strlen(buf); i++) {
284 if (!isdigit(buf[i]) && (buf[i] != '-')) {
285 printf("Phone numbers can contain only digits.\n");
295 /* Remove dashes if necessary */
296 if (dashes && result == buf) {
298 tmp1 = tmp2 = (char *)buf;
309 void get_new_info(old_info, new_info)
310 struct finger_info *old_info;
311 struct finger_info *new_info;
313 printf("Default values are printed inside of '[]'.\n");
314 printf("To accept the default, type <return>.\n");
315 printf("To have a blank entry, type the word '%s'.\n\n", BLANK);
317 #define GETINFO(m,v,n) \
318 new_info->v = strsave(ask(m, old_info->v, n))
320 GETINFO("Full name", fullname, FALSE);
321 GETINFO("Nickname", nickname, FALSE);
322 GETINFO("Home address (Ex: Atkinson 304)", home_address, FALSE);
323 GETINFO("Home phone number (Ex: 3141592)", home_phone, TRUE);
324 GETINFO("Office address (Exs: E40-342 or 2-108)",
325 office_address, FALSE);
326 GETINFO("Office phone (Ex: 3-1300)", office_phone, TRUE);
327 GETINFO("MIT department (Exs: 9, Biology, Information Services",
328 mit_department, FALSE);
329 GETINFO("MIT year (Exs: 1989, '91, Faculty, Grad)", mit_year, FALSE);
334 fprintf(stderr, "Usage: %s [user]\n", whoami);