login-utils/ch-common.c
chfn_chsh_cflags = $(SUID_CFLAGS) $(AM_CFLAGS)
chfn_chsh_ldflags = $(SUID_LDFLAGS) $(AM_LDFLAGS)
-chfn_chsh_ldadd = libcommon.la
+chfn_chsh_ldadd = libcommon.la $(READLINE_LIBS)
if CHFN_CHSH_PASSWORD
chfn_chsh_ldadd += -lpam
# include "auth.h"
#endif
+#ifdef HAVE_LIBREADLINE
+# define _FUNCTION_DEF
+# include <readline/readline.h>
+#endif
+
struct finfo {
char *full_name;
char *office;
char *def_val)
{
int len;
- char *ans;
- char buf[MAX_FIELD_SIZE + 2];
+ char *buf;
+#ifndef HAVE_LIBREADLINE
+ size_t dummy = 0;
+#endif
if (!def_val)
def_val = "";
while (true) {
printf("%s [%s]: ", question, def_val);
__fpurge(stdin);
- if (fgets(buf, sizeof(buf), stdin) == NULL)
+#ifdef HAVE_LIBREADLINE
+ if ((buf = readline(NULL)) == NULL)
+#else
+ if (getline(&buf, &dummy, stdin) < 0)
+#endif
errx(EXIT_FAILURE, _("Aborted."));
- ans = buf;
/* remove white spaces from string end */
- ltrim_whitespace((unsigned char *) ans);
- len = rtrim_whitespace((unsigned char *) ans);
- if (len == 0)
+ ltrim_whitespace((unsigned char *) buf);
+ len = rtrim_whitespace((unsigned char *) buf);
+ if (len == 0) {
+ free(buf);
return xstrdup(def_val);
- if (!strcasecmp(ans, "none")) {
+ }
+ if (!strcasecmp(buf, "none")) {
+ free(buf);
ctl->changed = 1;
return xstrdup("");
}
- if (check_gecos_string(question, ans) >= 0)
+ if (check_gecos_string(question, buf) >= 0)
break;
}
ctl->changed = 1;
- return xstrdup(ans);
+ return buf;
}
/*
# include "auth.h"
#endif
+#ifdef HAVE_LIBREADLINE
+# define _FUNCTION_DEF
+# include <readline/readline.h>
+#endif
+
struct sinfo {
char *username;
char *shell;
{
int len;
char *ans = NULL;
+#ifndef HAVE_LIBREADLINE
size_t dummy = 0;
- ssize_t sz;
+#endif
if (!oldshell)
oldshell = "";
printf("%s [%s]: ", question, oldshell);
- sz = getline(&ans, &dummy, stdin);
- if (sz == -1)
+#ifdef HAVE_LIBREADLINE
+ if ((ans = readline(NULL)) == NULL)
+#else
+ if (getline(&ans, &dummy, stdin) < 0)
+#endif
return NULL;
/* remove the newline at the end of ans. */
ltrim_whitespace((unsigned char *) ans);