A side effect is that the usage info can now go to stderr as it should.
* Line buffer struct.
*/
struct lbuf {
+ int (*output)(const char *);
char *buf;
- int continuation;
+ const char *continuation;
int indent;
int len;
int size;
int cols;
};
-void lbuf_init (struct lbuf *, char *, int, int, int);
-void lbuf_destroy (struct lbuf *);
-void lbuf_append (struct lbuf *, ...);
-void lbuf_append_quoted (struct lbuf *, const char *, ...);
-void lbuf_print (struct lbuf *);
+void lbuf_init(struct lbuf *, int (*)(const char *), int, const char *, int);
+void lbuf_destroy(struct lbuf *);
+void lbuf_append(struct lbuf *, ...);
+void lbuf_append_quoted(struct lbuf *, const char *, ...);
+void lbuf_print(struct lbuf *);
#endif /* _SUDO_LBUF_H */
#include "sudo_auth.h"
#include "insults.h"
-sudo_conv_t sudo_conv;
-
sudo_auth auth_switch[] = {
#ifdef AUTH_STANDALONE
AUTH_STANDALONE
static void lecture(int);
static void update_timestamp(char *, char *);
-extern sudo_conv_t sudo_conv;
-
/*
* This function only returns if the user can successfully
* verify who he/she is.
#endif
}
+static int
+output(const char *buf)
+{
+ struct sudo_conv_message msg;
+ struct sudo_conv_reply repl;
+
+ /* Call conversation function */
+ memset(&msg, 0, sizeof(msg));
+ msg.msg_type = SUDO_CONV_INFO_MSG;
+ msg.msg = buf;
+ memset(&repl, 0, sizeof(repl));
+ if (sudo_conv(1, &msg, &repl) == -1)
+ return 0;
+ return (int)strlen(buf);
+}
+
/*
* Print out privileges for the specified user.
* We only get here if the user is allowed to run something on this host.
*/
+/* XXX - conversation function or newlines in lbuf */
void
display_privs(snl, pw)
struct sudo_nss_list *snl;
/* Reset group vector so group matching works correctly. */
reset_groups(pw);
- lbuf_init(&lbuf, NULL, 4, 0, sudo_user.cols);
+ lbuf_init(&lbuf, output, 4, NULL, sudo_user.cols);
/* Display defaults from all sources. */
count = 0;
char *login_style;
#endif /* HAVE_BSD_AUTH_H */
sigaction_t saved_sa_int, saved_sa_quit, saved_sa_tstp;
+sudo_conv_t sudo_conv;
+
static char *runas_user;
static char *runas_group;
static struct sudo_nss_list *snl;
extern int tgetpass_flags; /* XXX */
extern int long_list;
extern uid_t timestamp_uid;
+extern sudo_conv_t sudo_conv;
#endif
#ifndef errno
extern int errno;
/*
- * Copyright (c) 2007-2009 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2007-2010 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
*/
void
-lbuf_init(struct lbuf *lbuf, char *buf, int indent, int continuation, int cols)
+lbuf_init(struct lbuf *lbuf, int (*output)(const char *),
+ int indent, const char *continuation, int cols)
{
+ lbuf->output = output;
lbuf->continuation = continuation;
lbuf->indent = indent;
lbuf->cols = cols;
void
lbuf_print(struct lbuf *lbuf)
{
- char *cp;
+ char *cp, save;
int i, have, contlen;
- contlen = lbuf->continuation ? 2 : 0;
+ contlen = lbuf->continuation ? strlen(lbuf->continuation) : 0;
/* For very small widths just give up... */
if (lbuf->cols <= lbuf->indent + contlen + 20) {
if (cp != lbuf->buf) {
/* indent continued lines */
for (i = 0; i < lbuf->indent; i++)
- putchar(' ');
+ lbuf->output(" ");
}
- fwrite(cp, need, 1, stdout);
+ /* NUL-terminate cp for the output function and restore afterwards */
+ save = cp[need];
+ cp[need] = '\0';
+ lbuf->output(cp);
+ cp[need] = save;
cp = ep;
/*
do {
cp++;
} while (isspace((unsigned char)*cp));
- if (lbuf->continuation) {
- putchar(' ');
- putchar(lbuf->continuation);
- }
+ if (contlen)
+ lbuf->output(lbuf->continuation);
}
- putchar('\n');
+ lbuf->output("\n");
}
done:
return(mode | flags);
}
+static int
+usage_out(const char *buf)
+{
+ return fputs(buf, stderr);
+}
+
/*
* Give usage message and exit.
* The actual usage strings are in sudo_usage.h for configure substitution.
* tty width.
*/
ulen = (int)strlen(getprogname()) + 8;
- lbuf_init(&lbuf, NULL, ulen, 0, user_details.ts_cols);
+ lbuf_init(&lbuf, usage_out, ulen, NULL, user_details.ts_cols);
for (i = 0; uvec[i] != NULL; i++) {
lbuf_append(&lbuf, "usage: ", getprogname(), uvec[i], NULL);
lbuf_print(&lbuf);