1 /*
2  * Font server main routine
3  */
4 /*
5 
6 Copyright 1990, 1991, 1998  The Open Group
7 
8 Permission to use, copy, modify, distribute, and sell this software and its
9 documentation for any purpose is hereby granted without fee, provided that
10 the above copyright notice appear in all copies and that both that
11 copyright notice and this permission notice appear in supporting
12 documentation.
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 Except as contained in this notice, the name of The Open Group shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from The Open Group.
27 
28  * Copyright 1990, 1991 Network Computing Devices;
29  * Portions Copyright 1987 by Digital Equipment Corporation
30  *
31  * Permission to use, copy, modify, distribute, and sell this software and
32  * its documentation for any purpose is hereby granted without fee, provided
33  * that the above copyright notice appear in all copies and that both that
34  * copyright notice and this permission notice appear in supporting
35  * documentation, and that the names of Network Computing Devices or Digital
36  * not be used in advertising or publicity pertaining to distribution
37  * of the software without specific, written prior permission.
38  *
39  * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
40  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
41  * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
42  * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
43  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
44  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
45  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
46  * THIS SOFTWARE.
47  */
48 
49 #include	"config.h"
50 
51 #include	<stdlib.h>
52 #include	<sys/types.h>
53 #include	<sys/stat.h>
54 #include	<X11/fonts/FS.h>
55 #include	<X11/fonts/FSproto.h>
56 #include	"clientstr.h"
57 #include	"fsresource.h"
58 #include	"misc.h"
59 #include	"globals.h"
60 #include	"servermd.h"
61 #include	"site.h"
62 #include	"dispatch.h"
63 #include	"extentst.h"
64 #include	"difs.h"
65 
66 char       *ConnectionInfo;
67 int         ConnInfoLen;
68 
69 static Bool create_connection_block(void);
70 
71 char       *configfilename;
72 
73 int
main(int argc,char * argv[])74 main(int argc, char *argv[])
75 {
76     int         i, oldumask;
77 
78     argcGlobal = argc;
79     argvGlobal = argv;
80 
81     configfilename = NULL;
82 
83     /* init stuff */
84     ProcessCmdLine(argc, argv);
85 
86     /*
87      * Do this first thing, to get any options that only take effect at
88      * startup time.  It is read again each time the server resets.
89      */
90     if (ReadConfigFile(configfilename) != FSSuccess) {
91 	FatalError("couldn't read config file\n");
92     }
93     InitErrors();
94 
95     /* make sure at least world write access is disabled */
96     if (((oldumask = umask(022)) & 002) == 002)
97 	(void)umask(oldumask);
98 
99     SetDaemonState();
100     SetUserId();
101 
102     while (1) {
103 	serverGeneration++;
104 	OsInit();
105 	if (serverGeneration == 1) {
106 	    /* do first time init */
107 	    CreateSockets(OldListenCount, OldListen);
108 	    InitProcVectors();
109 	    clients = (ClientPtr *) fsalloc(MAXCLIENTS * sizeof(ClientPtr));
110 	    if (!clients)
111 		FatalError("couldn't create client array\n");
112 	    for (i = MINCLIENT; i < MAXCLIENTS; i++)
113 		clients[i] = NullClient;
114 	    /* make serverClient */
115 	    serverClient = (ClientPtr) fsalloc(sizeof(ClientRec));
116 	    if (!serverClient)
117 		FatalError("couldn't create server client\n");
118 	}
119 	ResetSockets();
120 
121 	/* init per-cycle stuff */
122 	InitClient(serverClient, SERVER_CLIENT, (pointer) 0);
123 
124 	clients[SERVER_CLIENT] = serverClient;
125 	currentMaxClients = MINCLIENT;
126 	currentClient = serverClient;
127 
128 	if (!InitClientResources(serverClient))
129 	    FatalError("couldn't init server resources\n");
130 
131 	InitAtoms();
132 	InitFonts();
133 	SetConfigValues();
134 	if (!create_connection_block())
135 	    FatalError("couldn't create connection block\n");
136 
137 #ifdef DEBUG
138 	fprintf(stderr, "Entering Dispatch loop\n");
139 #endif
140 
141 	Dispatch();
142 
143 #ifdef DEBUG
144 	fprintf(stderr, "Leaving Dispatch loop\n");
145 #endif
146 
147 	/* clean up per-cycle stuff */
148 	if ((dispatchException & DE_TERMINATE) || drone_server)
149 	    break;
150 	fsfree(ConnectionInfo);
151 	/* note that we're parsing it again, for each time the server resets */
152 	if (ReadConfigFile(configfilename) != FSSuccess)
153 	    FatalError("couldn't read config file\n");
154     }
155 
156     CloseSockets();
157     CloseErrors();
158     exit(0);
159 }
160 
161 int
NotImplemented(void)162 NotImplemented(void)
163 {
164     NoopDDA();			/* dummy to get difsutils.o to link */
165     /* Getting here can become the next xfs exploit... so don't exit */
166     ErrorF("not implemented\n");
167 
168     return (FSBadImplementation);
169 }
170 
171 static Bool
create_connection_block(void)172 create_connection_block(void)
173 {
174     fsConnSetupAccept setup;
175     char       *pBuf;
176 
177     setup.release_number = VENDOR_RELEASE;
178     setup.vendor_len = strlen(VENDOR_STRING);
179     setup.max_request_len = MAX_REQUEST_SIZE;
180     setup.length = (SIZEOF(fsConnSetupAccept) + setup.vendor_len + 3) >> 2;
181 
182     ConnInfoLen = SIZEOF(fsConnSetupAccept) + ((setup.vendor_len + 3) & ~3);
183     ConnectionInfo = (char *) fsalloc(ConnInfoLen);
184     if (!ConnectionInfo)
185 	return FALSE;
186 
187     memmove( ConnectionInfo, (char *) &setup, SIZEOF(fsConnSetupAccept));
188     pBuf = ConnectionInfo + SIZEOF(fsConnSetupAccept);
189     memmove( pBuf, VENDOR_STRING, (int) setup.vendor_len);
190 
191     return TRUE;
192 }
193