/*
* Copyright (c) 1988-91 by Patrick J. Naughton.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* This file is provided AS IS with no warranties of any kind. The author
* shall have no liability with respect to the infringement of copyrights,
* trade secrets or any patents by this file or any part thereof. In no
* event will the author be liable for any lost revenue or profits or
* other special, indirect and consequential damages.
*/
/*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*-
* resource.c - resource management for xlock, the X Window System lockscreen.
*
* Revision History:
* 24-Jun-91: changed name to username.
* 06-Jun-91: Added flame mode.
* 24-May-91: Added -name and -usefirst and -resources.
* 16-May-91: Added random mode and pyro mode.
* 26-Mar-91: CheckResources: delay must be >= 0.
* 29-Oct-90: Added #include <ctype.h> for missing isupper() on some OS revs.
* moved -mode option, reordered Xrm database evaluation.
* 28-Oct-90: Added text strings.
* 26-Oct-90: Fix bug in mode specific options.
* 31-Jul-90: Fix ':' handling in parsefilepath
* 07-Jul-90: Created from resource work in xlock.c
*
*/
#include <stdio.h>
#include "xlock.h"
#include <netdb.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <X11/Xresource.h>
typedef struct {
const char *cmdline_arg;
void (*lp_init) ();
void (*lp_callback) ();
int def_delay;
int def_batchcount;
float def_saturation;
const char *desc;
} LockStruct;
};
#ifndef MAXHOSTNAMELEN
#endif
#ifdef X_NOT_STDC_ENV
extern char *getenv();
#endif
extern char *inet_ntoa();
#ifndef DEF_FILESEARCHPATH
#endif
static char *classname;
};
};
};
};
typedef struct {
const char *opt;
const char *desc;
} OptionStruct;
{"-help", "print out this message"},
{"-resources", "print default resource file to standard output"},
{"-display displayname", "X server to contact"},
{"-name resourcename", "class name to use for resources (default is XLock)"},
{"-delay usecs", "microsecond delay between screen updates"},
{"-batchcount num", "number of things per batch"},
{"-nice level", "nice level for xlock process"},
{"-timeout seconds", "number of seconds before password times out"},
{"-saturation value", "saturation of color ramp"},
{"-font fontname", "font to use for password prompt"},
{"-bg color", "background color to use for password prompt"},
{"-fg color", "foreground color to use for password prompt"},
{"-name string", "text string to use for Name prompt"},
{"-password string", "text string to use for Password prompt"},
{"-info string", "text string to use for instructions"},
{"-validate string", "text string to use for validating password message"},
{"-invalid string", "text string to use for invalid password message"},
};
const char *display;
const char *mode;
char *fontname;
char *background;
char *foreground;
char *text_name;
char *text_pass;
char *text_info;
char *text_valid;
char *text_invalid;
float saturation;
int nicelevel;
int delay;
int batchcount;
int timeout;
#define t_String 0
typedef struct {
void *var;
const char *name;
const char *class;
const char *def;
int type;
} argtype;
};
};
static void
{
for (i = 0; i < opDescEntries; i++) {
col = 3;
}
}
col = 3;
}
for (i = 1; i < NUMPROCS; i++) {
col = 3;
}
}
exit(1);
}
static void
Help(void)
{
int i;
for (i = 0; i < opDescEntries; i++) {
}
for (i = 0; i < NUMPROCS; i++) {
}
exit(0);
}
static void
DumpResources(void)
{
int i;
for (i = 0; i < NGENARGS; i++)
printf("%s.%s: %s\n",
for (i = 0; i < NUMPROCS - 1; i++) {
}
exit(0);
}
static void
LowerString(s)
char *s;
{
while (*s) {
if (isupper(*s))
*s += ('a' - 'A');
s++;
}
}
static void
const char *parentname,
const char *parentclass,
const char *name,
const char *class,
int valueType,
const char *def,
void *valuep) /* RETURN */
{
char *type;
const char *string;
int len;
/* 4036289. Limit the size of string to print. */
} else {
}
switch (valueType) {
case t_String:
{
if (s == (char *) NULL)
error("GetResource - couldn't allocate memory");
s[len] = '\0';
*((char **) valuep) = s;
}
break;
case t_Bool:
break;
case t_Int:
break;
case t_Float:
break;
}
}
static XrmDatabase
char *xfilesearchpath;
char *TypeName;
char *ClassName;
{
/* 4036289, do not use stack buffer, allocate this buffer from the heap*/
char *appdefaults;
char *src;
char *dst;
int buflen;
if (!appdefaults)
return NULL;
appdefaults[0] = '\0';
dst = appdefaults;
while (1) {
/* Scan through source, expanding % strings as necessary, and
passing completed paths to XrmGetFileDatabase when ':' or
end of string is found. To prevent buffer overflows (bug
4483090) each time we decide to append to the string, we
set appenddata to point to the data to be appended &
appendsize to the size to be appended, and then do all the
appending & size checking in one place at the end.
*/
char *appenddata;
int appendsize = 0;
if (*src == '%') {
src++;
switch (*src) {
case '%':
case ':':
appenddata = src++;
appendsize = 1;
break;
case 'T':
src++;
break;
case 'N':
src++;
break;
case 'S':
src++;
break;
default:
src++;
break;
}
} else if (*src == ':') {
dst = appdefaults;
*dst = '\0';
src++;
} else
break;
} else if (*src == '\0') {
break;
} else {
appenddata = src++;
appendsize = 1;
}
if (appendsize > 0) {
int newsize;
/* Grow by a bit more than we need so we don't have to
realloc constantly. */
if (appendsize > BUFSIZ) {
} else {
}
if (appdefaults) {
} else {
error("parsefilepath - couldn't allocate memory");
exit(1);
}
}
if (appendsize == 1) {
*dst++ = *appenddata;
} else {
dst += appendsize;
}
*dst = '\0';
}
}
if (appdefaults)
return database;
}
static void
{
/*
* only restrict access to other displays if we are locking and if the
* Remote resource is not set.
*/
if (nolock)
if (!remote && n
* Get the ip address of $DISPLAY and the machine name.
* If both are matching then allow to open display.
* ( also check against the ip addr list returned by gethostbyname.
* Otherwise, report error and exit.
* New Local Variables:
* display_ip contains IP address of the $DISPLAY
* host_ip contains IP address of the machine_name
* tmp_display contains the $DISPLAY - [:0.0 or :0]
* This fix will take care of long host name and IP address form.
*/
#ifdef IPv6
struct addrinfo *i, *j;
#else
char **hp;
char display_ip[MAXHOSTNAMELEN];
char host_ip[MAXHOSTNAMELEN];
struct hostent *host_display;
#endif
tmp_display[n] = '\0';
error("Can't get local hostname.\n");
#ifdef IPv6
error("Can't get address information for %s.\n",
= (struct sockaddr_in *) i->ai_addr;
= (struct sockaddr_in *) j->ai_addr;
badhost = 0;
}
= (struct sockaddr_in6 *) i->ai_addr;
= (struct sockaddr_in6 *) j->ai_addr;
badhost = 0;
}
}
}
}
}
#else
else
error("Can't get hostbyname.\n");
/* check against the list of Internet address */
badhost = 0;
break;
}
}
if ( badhost ) {
/* display has been replaced tmp_display because
* display will be in :0.0 format and tmp_display
* will have only the hostname/ip_address form.
*/
badhost = 0;
break;
}
}
}
#endif /* IPv6 */
if (badhost) {
*colon = (char) 0;
}
}
} else
display = ":0.0";
}
void
char *class;
{
case t_String:
break;
case t_Bool:
? "True" : "False");
break;
case t_Int:
break;
case t_Float:
break;
}
}
void
int argc,
char *argv[])
{
const char *homeenv;
char *userpath;
char *env;
char *serverString;
int i;
int modeLength;
/*
* get -name arg from command line so you can have different resource
* files for different configurations/machines etc...
*/
if (!homeenv)
homeenv = "";
"app-defaults", classname);
if (!userpath) {
if (env)
/* 4036289, Limit the string to print */
else
/* 4036289, Limit the string to print */
}
"off", &nolock);
"off", &remote);
open_display();
if (serverString) {
} else {
/* 4036289, Limit the string to print */
}
/*
* if random mode, then just grab a random entry from the table
*/
/* 4036289, Limit the string to print */
/* Parse the rest of the command line */
if (**argv != '-')
switch (argv[0][1]) {
case 'h':
Help();
/* NOTREACHED */
case 'r':
/* NOTREACHED */
default:
/* NOTREACHED */
}
}
/* the RDB is set, now query load the variables from the database */
for (i = 0; i < NGENARGS; i++)
for (i = 0; i < NMODEARGS; i++)
(void) XrmDestroyDatabase(RDB);
if (verbose) {
for (i = 0; i < NGENARGS; i++)
for (i = 0; i < NMODEARGS; i++)
}
}
void
CheckResources(void)
{
int i;
if (batchcount < 1)
Syntax("-batchcount argument must be positive.");
Syntax("-saturation argument must be between 0.0 and 1.0.");
if (delay < 0)
Syntax("-delay argument must be positive.");
for (i = 0; i < NUMPROCS; i++) {
break;
}
}
if (i == NUMPROCS) {
}
}