Skip to content

Commit

Permalink
snapshot of project "xterm", label xterm-333zb
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDickey committed Aug 13, 2018
1 parent 1c40198 commit 4d712b2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 58 deletions.
2 changes: 1 addition & 1 deletion MANIFEST
@@ -1,4 +1,4 @@
MANIFEST for xterm, version xterm-333za
MANIFEST for xterm, version xterm-333zb
--------------------------------------------------------------------------------
MANIFEST this file
256colres.h resource-definitions for 256-color mode
Expand Down
3 changes: 2 additions & 1 deletion data.h
@@ -1,4 +1,4 @@
/* $XTermId: data.h,v 1.133 2018/04/27 23:47:42 tom Exp $ */
/* $XTermId: data.h,v 1.134 2018/08/10 19:52:54 tom Exp $ */

/*
* Copyright 2002-2017,2018 by Thomas E. Dickey
Expand Down Expand Up @@ -155,6 +155,7 @@ typedef struct XTERM_RESOURCE {
char *icon_name;
char *term_name;
char *tty_modes;
char *valid_shells;

int minBufSize;
int maxBufSize;
Expand Down
161 changes: 107 additions & 54 deletions main.c
@@ -1,4 +1,4 @@
/* $XTermId: main.c,v 1.817 2018/08/10 13:30:37 tom Exp $ */
/* $XTermId: main.c,v 1.820 2018/08/10 22:25:49 tom Exp $ */

/*
* Copyright 2002-2017,2018 by Thomas E. Dickey
Expand Down Expand Up @@ -838,6 +838,7 @@ static XtResource application_resources[] =
Sres(XtNiconName, XtCIconName, icon_name, NULL),
Sres("termName", "TermName", term_name, NULL),
Sres("ttyModes", "TtyModes", tty_modes, NULL),
Sres("validShells", "ValidShells", valid_shells, NULL),
Bres("hold", "Hold", hold_screen, False),
Bres("utmpInhibit", "UtmpInhibit", utmpInhibit, False),
Bres("utmpDisplayId", "UtmpDisplayId", utmpDisplayId, True),
Expand Down Expand Up @@ -3359,29 +3360,6 @@ find_utmp(struct UTMP_STR *tofind)
#define USE_NO_DEV_TTY 0
#endif

#if defined(HAVE_GETUSERSHELL) && defined(HAVE_ENDUSERSHELL)
static Boolean
validShell(const char *pathname)
{
Boolean result = False;

if (validProgram(pathname)) {
char *q;

while ((q = getusershell()) != 0) {
TRACE(("...test \"%s\"\n", q));
if (!strcmp(q, pathname)) {
result = True;
break;
}
}
endusershell();
}

TRACE(("validShell %s ->%d\n", NonNull(pathname), result));
return result;
}
#else
static int
same_leaf(char *a, char *b)
{
Expand Down Expand Up @@ -3411,53 +3389,128 @@ same_file(const char *a, const char *b)
return result;
}

static int
findValidShell(const char *haystack, const char *needle)
{
int result = -1;
int count = -1;
const char *s, *t;
size_t have;
size_t want = strlen(needle);

TRACE(("findValidShell:\n%s\n", NonNull(haystack)));

for (s = t = haystack; (s != 0) && (*s != '\0'); s = t) {
++count;
if ((t = strchr(s, '\n')) == 0) {
t = s + strlen(s);
}
have = (size_t) (t - s);

if ((have >= want) && (*s != '#')) {
char *p = malloc(have + 1);

if (p != 0) {
char *q;

memcpy(p, s, have);
p[have] = '\0';
if ((q = x_strtrim(p)) != 0) {
TRACE(("...test %s\n", q));
if (!strcmp(q, needle)) {
result = count;
} else if (same_leaf(q, (char *) needle) &&
same_file(q, needle)) {
result = count;
}
free(q);
}
free(p);
}
if (result >= 0)
break;
}
while (*t == '\n') {
++t;
}
}
return result;
}

static int
ourValidShell(const char *pathname)
{
return findValidShell(x_strtrim(resource.valid_shells), pathname);
}

#if defined(HAVE_GETUSERSHELL) && defined(HAVE_ENDUSERSHELL)
static Boolean
validShell(const char *pathname)
{
int result = -1;

if (validProgram(pathname)) {
char *q;
int count = -1;

TRACE(("validShell:getusershell\n"));
while ((q = getusershell()) != 0) {
++count;
TRACE(("...test \"%s\"\n", q));
if (!strcmp(q, pathname)) {
result = count;
break;
}
}
endusershell();

if (result < 0)
result = ourValidShell(pathname);
}

TRACE(("validShell %s ->%d\n", NonNull(pathname), result));
return (result >= 0);
}
#else
/*
* Only set $SHELL for paths found in the standard location.
*/
static Boolean
validShell(const char *pathname)
{
Boolean result = False;
int result = -1;
const char *ok_shells = "/etc/shells";
char *blob;
struct stat sb;
size_t rc;
FILE *fp;

if (validProgram(pathname)
&& stat(ok_shells, &sb) == 0
&& (sb.st_mode & S_IFMT) == S_IFREG
&& ((size_t) sb.st_size > 0)
&& ((size_t) sb.st_size < (((size_t) ~0) - 2))
&& (blob = calloc((size_t) sb.st_size + 2, sizeof(char))) != 0) {
if ((fp = fopen(ok_shells, "r")) != 0) {
rc = fread(blob, sizeof(char), (size_t) sb.st_size, fp);
if (rc == (size_t) sb.st_size) {
char *p = blob;
char *q, *r;
blob[rc] = '\0';
while (!result && (q = strtok(p, "\n")) != 0) {
if ((r = x_strtrim(q)) != 0) {
TRACE(("...test \"%s\"\n", q));
if (!strcmp(q, pathname)) {
result = True;
} else if (same_leaf(q, (char *) pathname) &&
same_file(q, pathname)) {
result = True;
}
free(r);
if (result)
break;
}
p = 0;
if (validProgram(pathname)) {

TRACE(("validShell:%s\n", ok_shells));

if (stat(ok_shells, &sb) == 0
&& (sb.st_mode & S_IFMT) == S_IFREG
&& ((size_t) sb.st_size > 0)
&& ((size_t) sb.st_size < (((size_t) ~0) - 2))
&& (blob = calloc((size_t) sb.st_size + 2, sizeof(char))) != 0) {

if ((fp = fopen(ok_shells, "r")) != 0) {
rc = fread(blob, sizeof(char), (size_t) sb.st_size, fp);
fclose(fp);

if (rc == (size_t) sb.st_size) {
blob[rc] = '\0';
result = findValidShell(blob, pathname);
}
}
fclose(fp);
free(blob);
}
free(blob);
if (result < 0)
result = ourValidShell(pathname);
}
TRACE(("validShell %s ->%d\n", NonNull(pathname), result));
return result;
return (result > 0);
}
#endif

Expand Down
6 changes: 5 additions & 1 deletion xterm.log.html
Expand Up @@ -30,7 +30,7 @@
* sale, use or other dealings in this Software without prior written *
* authorization. *
*****************************************************************************
$XTermId: xterm.log.html,v 1.1888 2018/08/10 19:12:23 tom Exp $
$XTermId: xterm.log.html,v 1.1889 2018/08/10 20:59:04 tom Exp $
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

Expand Down Expand Up @@ -956,6 +956,10 @@ <h1>Contents</h1>
<h1><a name="xterm_dev" id="xterm_dev">Development</a></h1>

<ul>
<li>add resource-setting <code>validShells</code> which can be
used to augment the system's <code>/etc/shell</code> (prompted
by discussion with Paul Lampert).</li>

<li>stifle some useless warnings from lintian in
test-packages.</li>

Expand Down
18 changes: 17 additions & 1 deletion xterm.man
@@ -1,5 +1,5 @@
'\" t
.\" $XTermId: xterm.man,v 1.748 2018/07/13 20:06:47 tom Exp $
.\" $XTermId: xterm.man,v 1.749 2018/08/10 21:17:39 tom Exp $
.\"
.\" Copyright 1996-2017,2018 by Thomas E. Dickey
.\"
Expand Down Expand Up @@ -1985,6 +1985,18 @@ the system \fIutmp\fP log file.
If true, \fI\*n\fP will not try.
The default is \*(``false\*(''.
.TP 8
.B "validShells\fP (class\fB ValidShells\fP)"
Augment (add to) the system's \fI/etc/shells\fP,
when determining whether to set the \*(``SHELL\*('' environment
variable when running a given program.
.IP
The resource value is a list of lines (separated by newlines).
Each line holds one pathname.
\fI\*N\fP ignores any line beginning with \*(``#\*(''
after trimming leading/trailing whitespace from each line.
.IP
The default is an empty string.
.TP 8
.B "waitForMap\fP (class\fB WaitForMap\fP)"
Specifies whether or not \fI\*n\fP should wait for the initial window map
before starting the subprocess.
Expand Down Expand Up @@ -7682,6 +7694,10 @@ The actual pathnames given may differ on your system.
contains a list of valid shell programs,
used by \fI\*n\fP to decide if the \*(``SHELL\*('' environment
variable should be set for the process started by \fI\*n\fP.
.IP
On systems which have the \fIgetusershell\fP function,
\fI\*n\fP will use that function rather than directly reading the file,
since the file may not be present if the system uses default settings.
.TP 5
\fI/etc/utmp\fP
the system logfile, which records user logins.
Expand Down

0 comments on commit 4d712b2

Please sign in to comment.