Use number of tty columns that is passed in user_info instead of
getting it directly in the lbuf code.
This commit is contained in:
@@ -28,9 +28,10 @@ struct lbuf {
|
|||||||
int indent;
|
int indent;
|
||||||
int len;
|
int len;
|
||||||
int size;
|
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_destroy (struct lbuf *);
|
||||||
void lbuf_append (struct lbuf *, ...);
|
void lbuf_append (struct lbuf *, ...);
|
||||||
void lbuf_append_quoted (struct lbuf *, const char *, ...);
|
void lbuf_append_quoted (struct lbuf *, const char *, ...);
|
||||||
|
@@ -240,7 +240,7 @@ display_privs(snl, pw)
|
|||||||
/* Reset group vector so group matching works correctly. */
|
/* Reset group vector so group matching works correctly. */
|
||||||
reset_groups(pw);
|
reset_groups(pw);
|
||||||
|
|
||||||
lbuf_init(&lbuf, NULL, 4, 0);
|
lbuf_init(&lbuf, NULL, 4, 0, sudo_user.cols);
|
||||||
|
|
||||||
/* Display defaults from all sources. */
|
/* Display defaults from all sources. */
|
||||||
count = 0;
|
count = 0;
|
||||||
|
@@ -1280,6 +1280,14 @@ deserialize_info(char * const settings[], char * const user_info[])
|
|||||||
user_shost = estrndup(user_host, (size_t)(p - user_host));
|
user_shost = estrndup(user_host, (size_t)(p - user_host));
|
||||||
continue;
|
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
|
#undef MATCHES
|
||||||
|
@@ -65,6 +65,8 @@ struct sudo_user {
|
|||||||
int ngroups;
|
int ngroups;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
uid_t gid;
|
uid_t gid;
|
||||||
|
int lines;
|
||||||
|
int cols;
|
||||||
GETGROUPS_T *groups;
|
GETGROUPS_T *groups;
|
||||||
struct list_member *env_vars;
|
struct list_member *env_vars;
|
||||||
#ifdef HAVE_SELINUX
|
#ifdef HAVE_SELINUX
|
||||||
|
36
src/lbuf.c
36
src/lbuf.c
@@ -53,39 +53,16 @@
|
|||||||
#include "missing.h"
|
#include "missing.h"
|
||||||
#include "lbuf.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
|
* TODO: add support for embedded newlines in lbufs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
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->continuation = continuation;
|
||||||
lbuf->indent = indent;
|
lbuf->indent = indent;
|
||||||
|
lbuf->cols = cols;
|
||||||
lbuf->len = 0;
|
lbuf->len = 0;
|
||||||
lbuf->size = 0;
|
lbuf->size = 0;
|
||||||
lbuf->buf = NULL;
|
lbuf->buf = NULL;
|
||||||
@@ -188,14 +165,11 @@ lbuf_print(struct lbuf *lbuf)
|
|||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
int i, have, contlen;
|
int i, have, contlen;
|
||||||
static int cols = -1;
|
|
||||||
|
|
||||||
if (cols == -1)
|
|
||||||
cols = get_ttycols();
|
|
||||||
contlen = lbuf->continuation ? 2 : 0;
|
contlen = lbuf->continuation ? 2 : 0;
|
||||||
|
|
||||||
/* For very small widths just give up... */
|
/* For very small widths just give up... */
|
||||||
if (cols <= lbuf->indent + contlen + 20) {
|
if (lbuf->cols <= lbuf->indent + contlen + 20) {
|
||||||
puts(lbuf->buf);
|
puts(lbuf->buf);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@@ -205,7 +179,7 @@ lbuf_print(struct lbuf *lbuf)
|
|||||||
* boundary.
|
* boundary.
|
||||||
*/
|
*/
|
||||||
cp = lbuf->buf;
|
cp = lbuf->buf;
|
||||||
have = cols;
|
have = lbuf->cols;
|
||||||
while (cp != NULL && *cp != '\0') {
|
while (cp != NULL && *cp != '\0') {
|
||||||
char *ep;
|
char *ep;
|
||||||
int need = lbuf->len - (int)(cp - lbuf->buf);
|
int need = lbuf->len - (int)(cp - lbuf->buf);
|
||||||
@@ -234,7 +208,7 @@ lbuf_print(struct lbuf *lbuf)
|
|||||||
* the whitespace, and print a line continuaton char if needed.
|
* the whitespace, and print a line continuaton char if needed.
|
||||||
*/
|
*/
|
||||||
if (cp != NULL) {
|
if (cp != NULL) {
|
||||||
have = cols - lbuf->indent;
|
have = lbuf->cols - lbuf->indent;
|
||||||
do {
|
do {
|
||||||
cp++;
|
cp++;
|
||||||
} while (isspace((unsigned char)*cp));
|
} while (isspace((unsigned char)*cp));
|
||||||
|
@@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
/* XXX - prune this */
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
@@ -52,12 +50,14 @@
|
|||||||
|
|
||||||
#include <sudo_usage.h>
|
#include <sudo_usage.h>
|
||||||
#include "sudo.h"
|
#include "sudo.h"
|
||||||
#include "lbuf.h" /* XXX */
|
#include "lbuf.h"
|
||||||
|
|
||||||
/* For getopt(3) */
|
/* For getopt(3) */
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
|
extern struct user_details user_details;
|
||||||
|
|
||||||
/* XXX - better home for these and extern in header file */
|
/* XXX - better home for these and extern in header file */
|
||||||
int tgetpass_flags;
|
int tgetpass_flags;
|
||||||
int user_closefrom = -1;
|
int user_closefrom = -1;
|
||||||
@@ -376,7 +376,6 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
|
|||||||
/*
|
/*
|
||||||
* Give usage message and exit.
|
* Give usage message and exit.
|
||||||
* The actual usage strings are in sudo_usage.h for configure substitution.
|
* The actual usage strings are in sudo_usage.h for configure substitution.
|
||||||
* XXX - avoid lbuf usage
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
usage(int exit_val)
|
usage(int exit_val)
|
||||||
@@ -405,7 +404,7 @@ usage(int exit_val)
|
|||||||
* tty width.
|
* tty width.
|
||||||
*/
|
*/
|
||||||
ulen = (int)strlen(getprogname()) + 8;
|
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++) {
|
for (i = 0; uvec[i] != NULL; i++) {
|
||||||
lbuf_append(&lbuf, "usage: ", getprogname(), uvec[i], NULL);
|
lbuf_append(&lbuf, "usage: ", getprogname(), uvec[i], NULL);
|
||||||
lbuf_print(&lbuf);
|
lbuf_print(&lbuf);
|
||||||
|
@@ -154,16 +154,16 @@ main(int argc, char *argv[], char *envp[])
|
|||||||
disable_coredumps();
|
disable_coredumps();
|
||||||
fix_fds();
|
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. */
|
/* Parse command line arguments. */
|
||||||
sudo_mode = parse_args(Argc, Argv, &nargc, &nargv, &settings, &env_add);
|
sudo_mode = parse_args(Argc, Argv, &nargc, &nargv, &settings, &env_add);
|
||||||
|
|
||||||
/* Read sudo.conf and load plugins. */
|
/* Read sudo.conf and load plugins. */
|
||||||
sudo_load_plugins(_PATH_SUDO_CONF, &policy_plugin, &io_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. */
|
/* Open each plugin. */
|
||||||
ok = policy_plugin.u.policy->open(SUDO_API_VERSION, sudo_conversation,
|
ok = policy_plugin.u.policy->open(SUDO_API_VERSION, sudo_conversation,
|
||||||
settings, user_info, envp);
|
settings, user_info, envp);
|
||||||
|
Reference in New Issue
Block a user