#define false 0
#define true 1
-static char *whoami;
-
static char buf[1024];
struct finfo {
}
int main (int argc, char **argv) {
- char *cp;
uid_t uid;
struct finfo oldf, newf;
boolean interactive;
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- /* whoami is the program name for error messages */
- whoami = argv[0];
- if (! whoami) whoami = "chfn";
- for (cp = whoami; *cp; cp++)
- if (*cp == '/') whoami = cp + 1;
-
/*
* "oldf" contains the users original finger information.
* "newf" contains the changed finger information, and contains NULL
if (! newf.username) {
parse_passwd (getpwuid (uid), &oldf);
if (! oldf.username)
- errx(EXIT_FAILURE, _("%s: you (user %d) don't exist."), whoami, uid);
+ errx(EXIT_FAILURE, _("you (user %d) don't exist."), uid);
}
else {
parse_passwd (getpwnam (newf.username), &oldf);
if (! oldf.username)
- errx(EXIT_FAILURE, _("%s: user \"%s\" does not exist."),
- whoami, newf.username);
+ errx(EXIT_FAILURE, _("user \"%s\" does not exist."),
+ newf.username);
}
if (!(is_local(oldf.username)))
if (getprevcon(&user_context) < 0)
user_context = NULL;
- errx(EXIT_FAILURE, _("%s: %s is not authorized to change "
+ errx(EXIT_FAILURE, _("%s is not authorized to change "
"the finger info of %s"),
- whoami, user_context ? : _("Unknown user context"),
+ user_context ? : _("Unknown user context"),
oldf.username);
}
}
retcode = pam_start("chfn", oldf.username, &conv, &pamh);
if(retcode != PAM_SUCCESS)
- errx(EXIT_FAILURE, _("%s: PAM failure, aborting: %s"),
- whoami, pam_strerror(pamh, retcode));
+ errx(EXIT_FAILURE, _("PAM failure, aborting: %s"),
+ pam_strerror(pamh, retcode));
retcode = pam_authenticate(pamh, 0);
PAM_FAIL_CHECK(pamh, retcode);
info_given = true;
status = 0;
- xstrncpy (buf, whoami, sizeof(buf)-128);
- strcat (buf, ": ");
-
/* now store the argument */
switch (c) {
case 'f':
pinfo->full_name = optarg;
- strcat (buf, "full name");
- status = check_gecos_string (buf, optarg);
+ status = check_gecos_string (_("Name"), optarg);
break;
case 'o':
pinfo->office = optarg;
- strcat (buf, "office");
- status = check_gecos_string (buf, optarg);
+ status = check_gecos_string (_("Office"), optarg);
break;
case 'p':
pinfo->office_phone = optarg;
- strcat (buf, "office phone");
- status = check_gecos_string (buf, optarg);
+ status = check_gecos_string (_("Office Phone"), optarg);
break;
case 'h':
pinfo->home_phone = optarg;
- strcat (buf, "home phone");
- status = check_gecos_string (buf, optarg);
+ status = check_gecos_string (_("Home Phone"), optarg);
break;
default:
usage (stderr);
if (! def_val) def_val = "";
printf("%s [%s]: ", question, def_val);
*buf = 0;
- if (fgets (buf, sizeof (buf), stdin) == NULL) {
- printf (_("\nAborted.\n"));
- exit (EXIT_FAILURE);
- }
+ if (fgets (buf, sizeof (buf), stdin) == NULL)
+ errx (EXIT_FAILURE, _("Aborted."));
/* remove the newline at the end of buf. */
ans = buf;
while (isspace (*ans)) ans++;
unsigned int i, c;
if (strlen(gecos) > MAX_FIELD_SIZE) {
- if (msg != NULL)
- printf("%s: ", msg);
- printf(_("field is too long.\n"));
+ if (msg)
+ warnx (_("field %s is too long"), msg);
+ else
+ warnx (_("field is too long"));
return -1;
}
for (i = 0; i < strlen (gecos); i++) {
c = gecos[i];
if (c == ',' || c == ':' || c == '=' || c == '"' || c == '\n') {
- if (msg) printf ("%s: ", msg);
- printf (_("'%c' is not allowed.\n"), c);
+ if (msg)
+ warnx (_("%s: '%c' is not allowed"), msg, c);
+ else
+ warnx (_("'%c' is not allowed"), c);
return -1;
}
if (iscntrl (c)) {
- if (msg) printf ("%s: ", msg);
- printf (_("Control characters are not allowed.\n"));
+ if (msg)
+ warnx (_("%s: control characters are not allowed"), msg);
+ else
+ warnx (_("control characters are not allowed"));
return -1;
}
}
/* write the new struct passwd to the passwd file. */
pinfo->pw->pw_gecos = gecos;
if (setpwnam (pinfo->pw) < 0) {
- perror ("setpwnam");
+ warn ("setpwnam");
printf( _("Finger information *NOT* changed. Try again later.\n" ));
return -1;
}