resource.c revision 546
/*
* 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.
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* 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,
* to whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* 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
* OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Except as contained in this notice, the name of a copyright holder
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* of the copyright holder.
*/
/*-
* 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
*
*/
#pragma ident "@(#)resource.c 35.15 09/18/08 16:24:30 SunSoft"
#include <stdio.h>
#include "xlock.h"
#include <netdb.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <X11/Xresource.h>
/*
* Declare external interface routines for supported screen savers.
*/
extern void inithop();
extern void drawhop();
extern void initlife();
extern void drawlife();
extern void initqix();
extern void drawqix();
extern void initimage();
extern void drawimage();
extern void initblank();
extern void drawblank();
extern void initswarm();
extern void drawswarm();
extern void initrotor();
extern void drawrotor();
extern void initpyro();
extern void drawpyro();
extern void initflame();
extern void drawflame();
typedef struct {
char *cmdline_arg;
void (*lp_init) ();
void (*lp_callback) ();
int def_delay;
int def_batchcount;
float def_saturation;
char *desc;
} LockStruct;
static char randomstring[] = "random";
static LockStruct LockProcs[] = {
};
#ifndef MAXHOSTNAMELEN
#endif
#ifdef X_NOT_STDC_ENV
extern char *getenv();
#endif
extern char *inet_ntoa();
#ifndef DEF_FILESEARCHPATH
#define DEF_FILESEARCHPATH "/usr/lib/X11/%T/%N%S"
#endif
#define DEF_DISPLAY ":0"
#define DEF_MODE "life"
#define DEF_FONT "-b&h-lucida-medium-r-normal-sans-24-*-*-*-*-*-iso8859-1"
#define DEF_BG "White"
#define DEF_FG "Black"
#define DEF_NAME "Name: "
#define DEF_PASS "Password: "
#define DEF_INFO "Enter password to unlock; select icon to lock."
#define DEF_VALID "Validating login..."
#define DEF_INVALID "Invalid login."
#define DEF_CLASSNAME "XLock"
static char *classname;
static XrmOptionDescRec genTable[] = {
};
static XrmOptionDescRec modeTable[] = {
};
#define MODESPECIFIER0 ".delay"
#define MODESPECIFIER1 ".batchcount"
#define MODESPECIFIER2 ".saturation"
static XrmOptionDescRec cmdlineTable[] = {
};
static XrmOptionDescRec nameTable[] = {
};
typedef struct {
char *opt;
char *desc;
} OptionStruct;
static OptionStruct opDesc[] = {
{"-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"},
};
char *display;
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
#define t_Float 1
#define t_Int 2
#define t_Bool 3
typedef struct {
char *name;
char *class;
char *def;
int type;
} argtype;
};
};
static void
char *badOption;
{
for (i = 0; i < opDescEntries; i++) {
col = 3;
}
}
col = 3;
}
for (i = 1; i < NUMPROCS; i++) {
col = 3;
}
}
exit(1);
}
static void
Help()
{
int i;
for (i = 0; i < opDescEntries; i++) {
}
for (i = 0; i < NUMPROCS; i++) {
}
exit(0);
}
static 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
char *parentname;
char *parentclass;
char *name;
char *class;
int valueType;
char *def;
{
char *type;
char *string;
int len;
/* 4036289. Limit the size of string to print. */
} else {
}
switch (valueType) {
case t_String:
{
if (s == (char *) NULL)
error("%s: 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("%s: 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 *localhostaddr;
struct addrinfo *otherhostaddr;
struct addrinfo *i, *j;
#else
char **hp;
char display_ip[MAXHOSTNAMELEN];
char host_ip[MAXHOSTNAMELEN];
struct hostent *host_display;
#endif
int badhost = 1;
char hostname[MAXHOSTNAMELEN];
tmp_display[n] = '\0';
error("%s: Can't get local hostname.\n");
#ifdef IPv6
error("%s: Can't get address information for %s.\n",
struct sockaddr_in *sinA
= (struct sockaddr_in *) i->ai_addr;
struct sockaddr_in *sinB
= (struct sockaddr_in *) j->ai_addr;
badhost = 0;
}
struct sockaddr_in6 *sinA
= (struct sockaddr_in6 *) i->ai_addr;
struct sockaddr_in6 *sinB
= (struct sockaddr_in6 *) j->ai_addr;
badhost = 0;
}
}
}
}
}
#else
else
error("%s: 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[];
{
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 */
}
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++)
}
}
{
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) {
}
}