getting it directly in the lbuf code.
int indent;
int len;
int size;
+ int cols;
};
-void lbuf_init (struct lbuf *, char *, int, int);
+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 *, ...);
/* Reset group vector so group matching works correctly. */
reset_groups(pw);
- lbuf_init(&lbuf, NULL, 4, 0);
+ lbuf_init(&lbuf, NULL, 4, 0, sudo_user.cols);
/* Display defaults from all sources. */
count = 0;
user_shost = estrndup(user_host, (size_t)(p - user_host));
continue;
}
+ if (MATCHES(*cur, "lines=")) {
+ sudo_user.lines = atoi(*cur + sizeof("lines=") - 1);
+ continue;
+ }
+ if (MATCHES(*cur, "cols=")) {
+ sudo_user.cols = atoi(*cur + sizeof("cols=") - 1);
+ continue;
+ }
}
#undef MATCHES
int ngroups;
uid_t uid;
uid_t gid;
+ int lines;
+ int cols;
GETGROUPS_T *groups;
struct list_member *env_vars;
#ifdef HAVE_SELINUX
#include "missing.h"
#include "lbuf.h"
-#if !defined(TIOCGSIZE) && defined(TIOCGWINSZ)
-# define TIOCGSIZE TIOCGWINSZ
-# define ttysize winsize
-# define ts_cols ws_col
-#endif
-
-int
-get_ttycols(void)
-{
- char *p;
- int cols;
-#ifdef TIOCGSIZE
- struct ttysize win;
-
- if (ioctl(STDERR_FILENO, TIOCGSIZE, &win) == 0 && win.ts_cols != 0)
- return((int)win.ts_cols);
-#endif
-
- /* Fall back on $COLUMNS. */
- if ((p = getenv("COLUMNS")) == NULL || (cols = atoi(p)) <= 0)
- cols = 80;
- return(cols);
-}
-
/*
* TODO: add support for embedded newlines in lbufs
*/
void
-lbuf_init(struct lbuf *lbuf, char *buf, int indent, int continuation)
+lbuf_init(struct lbuf *lbuf, char *buf, int indent, int continuation, int cols)
{
lbuf->continuation = continuation;
lbuf->indent = indent;
+ lbuf->cols = cols;
lbuf->len = 0;
lbuf->size = 0;
lbuf->buf = NULL;
{
char *cp;
int i, have, contlen;
- static int cols = -1;
- if (cols == -1)
- cols = get_ttycols();
contlen = lbuf->continuation ? 2 : 0;
/* For very small widths just give up... */
- if (cols <= lbuf->indent + contlen + 20) {
+ if (lbuf->cols <= lbuf->indent + contlen + 20) {
puts(lbuf->buf);
goto done;
}
* boundary.
*/
cp = lbuf->buf;
- have = cols;
+ have = lbuf->cols;
while (cp != NULL && *cp != '\0') {
char *ep;
int need = lbuf->len - (int)(cp - lbuf->buf);
* the whitespace, and print a line continuaton char if needed.
*/
if (cp != NULL) {
- have = cols - lbuf->indent;
+ have = lbuf->cols - lbuf->indent;
do {
cp++;
} while (isspace((unsigned char)*cp));
#include <config.h>
-/* XXX - prune this */
-
#include <sys/types.h>
#include <sys/param.h>
#include <sudo_usage.h>
#include "sudo.h"
-#include "lbuf.h" /* XXX */
+#include "lbuf.h"
/* For getopt(3) */
extern char *optarg;
extern int optind;
+extern struct user_details user_details;
+
/* XXX - better home for these and extern in header file */
int tgetpass_flags;
int user_closefrom = -1;
/*
* Give usage message and exit.
* The actual usage strings are in sudo_usage.h for configure substitution.
- * XXX - avoid lbuf usage
*/
static void
usage(int exit_val)
* tty width.
*/
ulen = (int)strlen(getprogname()) + 8;
- lbuf_init(&lbuf, NULL, ulen, 0);
+ lbuf_init(&lbuf, NULL, ulen, 0, user_details.ts_cols);
for (i = 0; uvec[i] != NULL; i++) {
lbuf_append(&lbuf, "usage: ", getprogname(), uvec[i], NULL);
lbuf_print(&lbuf);
disable_coredumps();
fix_fds();
+ /* Fill in user_info with user name, uid, cwd, etc. */
+ memset(&user_details, 0, sizeof(user_details));
+ user_info = get_user_info(&user_details);
+
/* Parse command line arguments. */
sudo_mode = parse_args(Argc, Argv, &nargc, &nargv, &settings, &env_add);
/* Read sudo.conf and load plugins. */
sudo_load_plugins(_PATH_SUDO_CONF, &policy_plugin, &io_plugins);
- /* Fill in user_info with user name, uid, cwd, etc. */
- memset(&user_details, 0, sizeof(user_details));
- user_info = get_user_info(&user_details);
-
/* Open each plugin. */
ok = policy_plugin.u.policy->open(SUDO_API_VERSION, sudo_conversation,
settings, user_info, envp);