+ do {
+ printf("\nName [%s]: ", defaults->name);
+ (void) fgets(in_str, BUFSIZ, stdin);
+ if (special_case(in_str, defaults->name))
+ break;
+ } while (illegal_input(in_str));
+ (void) strcpy(answer, in_str);
+ /*
+ * Get room number.
+ */
+ do {
+ printf("Room number (Exs: 597E or 197C) [%s]: ",
+ defaults->office_num);
+ (void) fgets(in_str, BUFSIZ, stdin);
+ if (special_case(in_str, defaults->office_num))
+ break;
+ } while (illegal_input(in_str) || illegal_building(in_str));
+ (void) strcat(strcat(answer, ","), in_str);
+ /*
+ * Get office phone number.
+ * Remove hyphens and 642, x2, or 2 prefixes if present.
+ */
+ do {
+ printf("Office Phone (Ex: 1632) [%s]: ",
+ defaults->office_phone);
+ (void) fgets(in_str, BUFSIZ, stdin);
+ if (special_case(in_str, defaults->office_phone))
+ break;
+ remove_hyphens(in_str);
+ if (strlen(in_str) == 8 && strcmpn(in_str, "642", 3) == 0)
+ (void) strcpy(in_str, in_str+3);
+ if (strlen(in_str) == 7 && strcmpn(in_str, "x2", 2) == 0)
+ (void) strcpy(in_str, in_str+2);
+ if (strlen(in_str) == 6 && in_str[0] == '2')
+ (void) strcpy(in_str, in_str+1);
+ } while (illegal_input(in_str) || not_all_digits(in_str)
+ || wrong_length(in_str, 4));
+ (void) strcat(strcat(answer, ","), in_str);
+ /*
+ * Get home phone number.
+ * Remove hyphens if present.
+ */
+ do {
+ printf("Home Phone (Ex: 9875432) [%s]: ", defaults->home_phone);
+ (void) fgets(in_str, BUFSIZ, stdin);
+ if (special_case(in_str, defaults->home_phone))
+ break;
+ remove_hyphens(in_str);
+ } while (illegal_input(in_str) || not_all_digits(in_str));
+ (void) strcat(strcat(answer, ","), in_str);
+ if (strcmp(answer, pwd->pw_gecos) == 0) {
+ printf("Finger information unchanged.\n");
+ exit(1);
+ }
+ return (answer);
+}
+
+/*
+ * Prints an error message if a ':' or a newline is found in the string.
+ * A message is also printed if the input string is too long.
+ * The password file uses :'s as seperators, and are not allowed in the "gcos"
+ * field. Newlines serve as delimiters between users in the password file,
+ * and so, those too, are checked for. (I don't think that it is possible to
+ * type them in, but better safe than sorry)
+ *
+ * Returns '1' if a colon or newline is found or the input line is too long.
+ */
+illegal_input(input_str)
+ char *input_str;
+{
+ char *ptr;
+ int error_flag = 0;
+ int length = strlen(input_str);
+
+ if (index(input_str, ':')) {
+ printf("':' is not allowed.\n");
+ error_flag = 1;
+ }
+ if (input_str[length-1] != '\n') {
+ /* the newline and the '\0' eat up two characters */
+ printf("Maximum number of characters allowed is %d\n",
+ BUFSIZ-2);
+ /* flush the rest of the input line */
+ while (getchar() != '\n')
+ /* void */;
+ error_flag = 1;
+ }
+ /*
+ * Delete newline by shortening string by 1.
+ */
+ input_str[length-1] = '\0';
+ /*
+ * Don't allow control characters, etc in input string.
+ */
+ for (ptr=input_str; *ptr != '\0'; ptr++) {
+ if ((int) *ptr < 040) {
+ printf("Control characters are not allowed.\n");
+ error_flag = 1;
+ break;