105b261ecSmrg/***********************************************************
205b261ecSmrg
305b261ecSmrgCopyright 1987, 1998  The Open Group
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
705b261ecSmrgthe above copyright notice appear in all copies and that both that
805b261ecSmrgcopyright notice and this permission notice appear in supporting
905b261ecSmrgdocumentation.
1005b261ecSmrg
1105b261ecSmrgThe above copyright notice and this permission notice shall be included in
1205b261ecSmrgall copies or substantial portions of the Software.
1305b261ecSmrg
1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2005b261ecSmrg
2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be
2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings
2305b261ecSmrgin this Software without prior written authorization from The Open Group.
2405b261ecSmrg
2505b261ecSmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
2605b261ecSmrg
2705b261ecSmrg                        All Rights Reserved
2805b261ecSmrg
29f7df2e56SmrgPermission to use, copy, modify, and distribute this software and its
30f7df2e56Smrgdocumentation for any purpose and without fee is hereby granted,
3105b261ecSmrgprovided that the above copyright notice appear in all copies and that
32f7df2e56Smrgboth that copyright notice and this permission notice appear in
3305b261ecSmrgsupporting documentation, and that the name of Digital not be
3405b261ecSmrgused in advertising or publicity pertaining to distribution of the
35f7df2e56Smrgsoftware without specific, written prior permission.
3605b261ecSmrg
3705b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
3905b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
4305b261ecSmrgSOFTWARE.
4405b261ecSmrg
4505b261ecSmrg******************************************************************/
4605b261ecSmrg
4705b261ecSmrg#ifndef OS_H
4805b261ecSmrg#define OS_H
4905b261ecSmrg
5005b261ecSmrg#include "misc.h"
5105b261ecSmrg#include <stdarg.h>
52f7df2e56Smrg#include <stdint.h>
53f0d0f83fSmrg#if defined(HAVE_REALLOCARRAY)
54f0d0f83fSmrg#include <stdlib.h>       /* for reallocarray */
55f0d0f83fSmrg#endif
5665b04b38Smrg#include <string.h>
577e31ba66Smrg#ifdef MONOTONIC_CLOCK
587e31ba66Smrg#include <time.h>
597e31ba66Smrg#endif
6005b261ecSmrg
6105b261ecSmrg#define SCREEN_SAVER_ON   0
6205b261ecSmrg#define SCREEN_SAVER_OFF  1
6305b261ecSmrg#define SCREEN_SAVER_FORCER 2
6405b261ecSmrg#define SCREEN_SAVER_CYCLE  3
6505b261ecSmrg
6605b261ecSmrg#ifndef MAX_REQUEST_SIZE
6705b261ecSmrg#define MAX_REQUEST_SIZE 65535
6805b261ecSmrg#endif
6905b261ecSmrg#ifndef MAX_BIG_REQUEST_SIZE
7005b261ecSmrg#define MAX_BIG_REQUEST_SIZE 4194303
7105b261ecSmrg#endif
7205b261ecSmrg
7305b261ecSmrgtypedef struct _FontPathRec *FontPathPtr;
7405b261ecSmrgtypedef struct _NewClientRec *NewClientPtr;
7505b261ecSmrg
76f7df2e56Smrg#ifndef xnfalloc
7705b261ecSmrg#define xnfalloc(size) XNFalloc((unsigned long)(size))
78f7df2e56Smrg#define xnfcalloc(_num, _size) XNFcallocarray((_num), (_size))
79f7df2e56Smrg#define xnfrealloc(ptr, size) XNFrealloc((void *)(ptr), (unsigned long)(size))
8005b261ecSmrg
8105b261ecSmrg#define xstrdup(s) Xstrdup(s)
8205b261ecSmrg#define xnfstrdup(s) XNFstrdup(s)
83f7df2e56Smrg
84f7df2e56Smrg#define xallocarray(num, size) reallocarray(NULL, (num), (size))
85f7df2e56Smrg#define xnfallocarray(num, size) XNFreallocarray(NULL, (num), (size))
86f7df2e56Smrg#define xnfreallocarray(ptr, num, size) XNFreallocarray((ptr), (num), (size))
8705b261ecSmrg#endif
8805b261ecSmrg
8905b261ecSmrg#include <stdio.h>
9005b261ecSmrg#include <stdarg.h>
91de0a7c19Smacallan#include <string.h>
92de0a7c19Smacallan#include <strings.h>
93de0a7c19Smacallan
9405b261ecSmrg
954202a189Smrg#ifdef DDXBEFORERESET
96f7df2e56Smrgextern void ddxBeforeReset(void);
9705b261ecSmrg#endif
9805b261ecSmrg
994202a189Smrg#ifdef DDXOSVERRORF
100f7df2e56Smrgextern _X_EXPORT void (*OsVendorVErrorFProc) (const char *,
101f7df2e56Smrg                                              va_list args)
102f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0);
1034202a189Smrg#endif
10405b261ecSmrg
1057e31ba66Smrgextern _X_EXPORT Bool WaitForSomething(Bool clients_are_ready);
106f7df2e56Smrg
107f7df2e56Smrgextern _X_EXPORT int ReadRequestFromClient(ClientPtr /*client */ );
10805b261ecSmrg
109f7df2e56Smrgextern _X_EXPORT int ReadFdFromClient(ClientPtr client);
11005b261ecSmrg
111f7df2e56Smrgextern _X_EXPORT int WriteFdToClient(ClientPtr client, int fd, Bool do_close);
112f7df2e56Smrg
113f7df2e56Smrgextern _X_EXPORT Bool InsertFakeRequest(ClientPtr /*client */ ,
114f7df2e56Smrg                                        char * /*data */ ,
115f7df2e56Smrg                                        int /*count */ );
11605b261ecSmrg
117f7df2e56Smrgextern _X_EXPORT void ResetCurrentRequest(ClientPtr /*client */ );
11805b261ecSmrg
1194202a189Smrgextern _X_EXPORT void FlushAllOutput(void);
12005b261ecSmrg
1214202a189Smrgextern _X_EXPORT void FlushIfCriticalOutputPending(void);
12205b261ecSmrg
1234202a189Smrgextern _X_EXPORT void SetCriticalOutputPending(void);
12405b261ecSmrg
125f7df2e56Smrgextern _X_EXPORT int WriteToClient(ClientPtr /*who */ , int /*count */ ,
126f7df2e56Smrg                                   const void * /*buf */ );
12705b261ecSmrg
1284202a189Smrgextern _X_EXPORT void ResetOsBuffers(void);
12905b261ecSmrg
1304202a189Smrgextern _X_EXPORT void NotifyParentProcess(void);
131637ac9abSmrg
1324202a189Smrgextern _X_EXPORT void CreateWellKnownSockets(void);
13305b261ecSmrg
1344202a189Smrgextern _X_EXPORT void ResetWellKnownSockets(void);
13505b261ecSmrg
1364202a189Smrgextern _X_EXPORT void CloseWellKnownConnections(void);
13705b261ecSmrg
138f7df2e56Smrgextern _X_EXPORT XID AuthorizationIDOfClient(ClientPtr /*client */ );
13905b261ecSmrg
140f7df2e56Smrgextern _X_EXPORT const char *ClientAuthorized(ClientPtr /*client */ ,
141f7df2e56Smrg                                              unsigned int /*proto_n */ ,
142f7df2e56Smrg                                              char * /*auth_proto */ ,
143f7df2e56Smrg                                              unsigned int /*string_n */ ,
144f7df2e56Smrg                                              char * /*auth_string */ );
14505b261ecSmrg
146f7df2e56Smrgextern _X_EXPORT void CloseDownConnection(ClientPtr /*client */ );
14705b261ecSmrg
1487e31ba66Smrgtypedef void (*NotifyFdProcPtr)(int fd, int ready, void *data);
14905b261ecSmrg
1507e31ba66Smrg#define X_NOTIFY_NONE   0x0
1517e31ba66Smrg#define X_NOTIFY_READ   0x1
1527e31ba66Smrg#define X_NOTIFY_WRITE  0x2
1537e31ba66Smrg#define X_NOTIFY_ERROR  0x4     /* don't need to select for, always reported */
15405b261ecSmrg
1557e31ba66Smrgextern _X_EXPORT Bool SetNotifyFd(int fd, NotifyFdProcPtr notify_fd, int mask, void *data);
15605b261ecSmrg
1577e31ba66Smrgstatic inline void RemoveNotifyFd(int fd)
1587e31ba66Smrg{
1597e31ba66Smrg    (void) SetNotifyFd(fd, NULL, X_NOTIFY_NONE, NULL);
1607e31ba66Smrg}
16105b261ecSmrg
162f7df2e56Smrgextern _X_EXPORT int OnlyListenToOneClient(ClientPtr /*client */ );
16305b261ecSmrg
1644202a189Smrgextern _X_EXPORT void ListenToAllClients(void);
16505b261ecSmrg
166f7df2e56Smrgextern _X_EXPORT void IgnoreClient(ClientPtr /*client */ );
16705b261ecSmrg
168f7df2e56Smrgextern _X_EXPORT void AttendClient(ClientPtr /*client */ );
16905b261ecSmrg
170f7df2e56Smrgextern _X_EXPORT void MakeClientGrabImpervious(ClientPtr /*client */ );
17105b261ecSmrg
172f7df2e56Smrgextern _X_EXPORT void MakeClientGrabPervious(ClientPtr /*client */ );
17305b261ecSmrg
174f7df2e56Smrgextern _X_EXPORT void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
175f7df2e56Smrg
176f7df2e56Smrgextern _X_EXPORT Bool AddClientOnOpenFD(int /* fd */ );
17705b261ecSmrg
1787e31ba66Smrg#ifdef MONOTONIC_CLOCK
1797e31ba66Smrgextern void ForceClockId(clockid_t /* forced_clockid */);
1807e31ba66Smrg#endif
1817e31ba66Smrg
1824202a189Smrgextern _X_EXPORT CARD32 GetTimeInMillis(void);
183f7df2e56Smrgextern _X_EXPORT CARD64 GetTimeInMicros(void);
18405b261ecSmrg
1857e31ba66Smrgextern _X_EXPORT void AdjustWaitForDelay(void *waitTime, int newdelay);
18605b261ecSmrg
187f7df2e56Smrgtypedef struct _OsTimerRec *OsTimerPtr;
18805b261ecSmrg
189f7df2e56Smrgtypedef CARD32 (*OsTimerCallback) (OsTimerPtr timer,
190f7df2e56Smrg                                   CARD32 time,
191f7df2e56Smrg                                   void *arg);
19205b261ecSmrg
1934202a189Smrgextern _X_EXPORT void TimerInit(void);
19405b261ecSmrg
195f7df2e56Smrgextern _X_EXPORT Bool TimerForce(OsTimerPtr /* timer */ );
19605b261ecSmrg
19705b261ecSmrg#define TimerAbsolute (1<<0)
19805b261ecSmrg#define TimerForceOld (1<<1)
19905b261ecSmrg
200f7df2e56Smrgextern _X_EXPORT OsTimerPtr TimerSet(OsTimerPtr timer,
201f7df2e56Smrg                                     int flags,
202f7df2e56Smrg                                     CARD32 millis,
203f7df2e56Smrg                                     OsTimerCallback func,
204f7df2e56Smrg                                     void *arg);
20505b261ecSmrg
2064202a189Smrgextern _X_EXPORT void TimerCheck(void);
207f7df2e56Smrgextern _X_EXPORT void TimerCancel(OsTimerPtr /* pTimer */ );
208f7df2e56Smrgextern _X_EXPORT void TimerFree(OsTimerPtr /* pTimer */ );
20905b261ecSmrg
2104202a189Smrgextern _X_EXPORT void SetScreenSaverTimer(void);
2114202a189Smrgextern _X_EXPORT void FreeScreenSaverTimer(void);
21205b261ecSmrg
213f7df2e56Smrgextern _X_EXPORT void AutoResetServer(int /*sig */ );
21405b261ecSmrg
215f7df2e56Smrgextern _X_EXPORT void GiveUp(int /*sig */ );
21605b261ecSmrg
2174202a189Smrgextern _X_EXPORT void UseMsg(void);
21805b261ecSmrg
219f7df2e56Smrgextern _X_EXPORT void ProcessCommandLine(int /*argc */ , char * /*argv */ []);
22005b261ecSmrg
221f7df2e56Smrgextern _X_EXPORT int set_font_authorizations(char **authorizations,
222f7df2e56Smrg                                             int *authlen,
223f7df2e56Smrg                                             void *client);
2244202a189Smrg
2254202a189Smrg/*
2264202a189Smrg * This function malloc(3)s buffer, terminating the server if there is not
2274202a189Smrg * enough memory.
2284202a189Smrg */
229f7df2e56Smrgextern _X_EXPORT void *
230f7df2e56SmrgXNFalloc(unsigned long /*amount */ );
231f7df2e56Smrg
2324202a189Smrg/*
2334202a189Smrg * This function calloc(3)s buffer, terminating the server if there is not
2344202a189Smrg * enough memory.
2354202a189Smrg */
236f7df2e56Smrgextern _X_EXPORT void *
237f7df2e56SmrgXNFcalloc(unsigned long /*amount */ ) _X_DEPRECATED;
238f7df2e56Smrg
239f7df2e56Smrg/*
240f7df2e56Smrg * This function calloc(3)s buffer, terminating the server if there is not
241f7df2e56Smrg * enough memory or the arguments overflow when multiplied
242f7df2e56Smrg */
243f7df2e56Smrgextern _X_EXPORT void *
244f7df2e56SmrgXNFcallocarray(size_t nmemb, size_t size);
245f7df2e56Smrg
2464202a189Smrg/*
2474202a189Smrg * This function realloc(3)s passed buffer, terminating the server if there is
2484202a189Smrg * not enough memory.
2494202a189Smrg */
250f7df2e56Smrgextern _X_EXPORT void *
251f7df2e56SmrgXNFrealloc(void * /*ptr */ , unsigned long /*amount */ );
252f7df2e56Smrg
253f7df2e56Smrg/*
254f7df2e56Smrg * This function reallocarray(3)s passed buffer, terminating the server if
255f7df2e56Smrg * there is not enough memory or the arguments overflow when multiplied.
256f7df2e56Smrg */
257f7df2e56Smrgextern _X_EXPORT void *
258f7df2e56SmrgXNFreallocarray(void *ptr, size_t nmemb, size_t size);
25905b261ecSmrg
2604202a189Smrg/*
2614202a189Smrg * This function strdup(3)s passed string. The only difference from the library
2624202a189Smrg * function that it is safe to pass NULL, as NULL will be returned.
2634202a189Smrg */
264f7df2e56Smrgextern _X_EXPORT char *
265f7df2e56SmrgXstrdup(const char *s);
26605b261ecSmrg
2674202a189Smrg/*
2684202a189Smrg * This function strdup(3)s passed string, terminating the server if there is
2694202a189Smrg * not enough memory. If NULL is passed to this function, NULL is returned.
2704202a189Smrg */
271f7df2e56Smrgextern _X_EXPORT char *
272f7df2e56SmrgXNFstrdup(const char *s);
27305b261ecSmrg
27465b04b38Smrg/* Include new X*asprintf API */
27565b04b38Smrg#include "Xprintf.h"
27665b04b38Smrg
27765b04b38Smrg/* Older api deprecated in favor of the asprintf versions */
278f7df2e56Smrgextern _X_EXPORT char *
279f7df2e56SmrgXprintf(const char *fmt, ...)
280f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 2)
281f7df2e56Smrg    _X_DEPRECATED;
282f7df2e56Smrgextern _X_EXPORT char *
283f7df2e56SmrgXvprintf(const char *fmt, va_list va)
284f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0)
285f7df2e56Smrg    _X_DEPRECATED;
286f7df2e56Smrgextern _X_EXPORT char *
287f7df2e56SmrgXNFprintf(const char *fmt, ...)
288f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 2)
289f7df2e56Smrg    _X_DEPRECATED;
290f7df2e56Smrgextern _X_EXPORT char *
291f7df2e56SmrgXNFvprintf(const char *fmt, va_list va)
292f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0)
293f7df2e56Smrg    _X_DEPRECATED;
29405b261ecSmrg
295f7df2e56Smrgtypedef void (*OsSigHandlerPtr) (int /* sig */ );
296f7df2e56Smrgtypedef int (*OsSigWrapperPtr) (int /* sig */ );
29705b261ecSmrg
298f7df2e56Smrgextern _X_EXPORT OsSigHandlerPtr
299f7df2e56SmrgOsSignal(int /* sig */ , OsSigHandlerPtr /* handler */ );
300f7df2e56Smrgextern _X_EXPORT OsSigWrapperPtr
301f7df2e56SmrgOsRegisterSigWrapper(OsSigWrapperPtr newWrap);
30205b261ecSmrg
3034202a189Smrgextern _X_EXPORT int auditTrailLevel;
3044202a189Smrg
305f7df2e56Smrgextern _X_EXPORT void
306f7df2e56SmrgLockServer(void);
307f7df2e56Smrgextern _X_EXPORT void
308f7df2e56SmrgUnlockServer(void);
3094202a189Smrg
310f7df2e56Smrgextern _X_EXPORT int
311f7df2e56SmrgOsLookupColor(int /*screen */ ,
312f7df2e56Smrg              char * /*name */ ,
313f7df2e56Smrg              unsigned /*len */ ,
314f7df2e56Smrg              unsigned short * /*pred */ ,
315f7df2e56Smrg              unsigned short * /*pgreen */ ,
316f7df2e56Smrg              unsigned short * /*pblue */ );
31705b261ecSmrg
318f7df2e56Smrgextern _X_EXPORT void
319f7df2e56SmrgOsInit(void);
32005b261ecSmrg
321f7df2e56Smrgextern _X_EXPORT void
322f7df2e56SmrgOsCleanup(Bool);
32305b261ecSmrg
324f7df2e56Smrgextern _X_EXPORT void
325f7df2e56SmrgOsVendorFatalError(const char *f, va_list args)
326f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0);
32705b261ecSmrg
328f7df2e56Smrgextern _X_EXPORT void
329f7df2e56SmrgOsVendorInit(void);
33005b261ecSmrg
331f7df2e56Smrgextern _X_EXPORT void
332f7df2e56SmrgOsBlockSignals(void);
33305b261ecSmrg
334f7df2e56Smrgextern _X_EXPORT void
335f7df2e56SmrgOsReleaseSignals(void);
3364202a189Smrg
337f7df2e56Smrgextern void
338f7df2e56SmrgOsResetSignals(void);
33905b261ecSmrg
340f7df2e56Smrgextern _X_EXPORT void
341f7df2e56SmrgOsAbort(void)
342f7df2e56Smrg    _X_NORETURN;
34305b261ecSmrg
344f7df2e56Smrg#if !defined(WIN32)
345f7df2e56Smrgextern _X_EXPORT int
346f7df2e56SmrgSystem(const char *);
347f7df2e56Smrgextern _X_EXPORT void *
348f7df2e56SmrgPopen(const char *, const char *);
349f7df2e56Smrgextern _X_EXPORT int
350f7df2e56SmrgPclose(void *);
351f7df2e56Smrgextern _X_EXPORT void *
352f7df2e56SmrgFopen(const char *, const char *);
353f7df2e56Smrgextern _X_EXPORT int
354f7df2e56SmrgFclose(void *);
355f7df2e56Smrg#else
35605b261ecSmrg
357f7df2e56Smrgextern const char *
358f7df2e56SmrgWin32TempDir(void);
35905b261ecSmrg
360f7df2e56Smrgextern int
361f7df2e56SmrgSystem(const char *cmdline);
36205b261ecSmrg
363f7df2e56Smrg#define Fopen(a,b) fopen(a,b)
364f7df2e56Smrg#define Fclose(a) fclose(a)
365f7df2e56Smrg#endif
36605b261ecSmrg
3677e31ba66Smrgextern _X_EXPORT Bool
3687e31ba66SmrgPrivsElevated(void);
3697e31ba66Smrg
370f7df2e56Smrgextern _X_EXPORT void
371f7df2e56SmrgCheckUserParameters(int argc, char **argv, char **envp);
372f7df2e56Smrgextern _X_EXPORT void
373f7df2e56SmrgCheckUserAuthorization(void);
374f7df2e56Smrg
375f7df2e56Smrgextern _X_EXPORT int
376f7df2e56SmrgAddHost(ClientPtr /*client */ ,
377f7df2e56Smrg        int /*family */ ,
378f7df2e56Smrg        unsigned /*length */ ,
379f7df2e56Smrg        const void * /*pAddr */ );
380f7df2e56Smrg
381f7df2e56Smrgextern _X_EXPORT Bool
382f7df2e56SmrgForEachHostInFamily(int family,
383f7df2e56Smrg                    Bool (*func)(
384f7df2e56Smrg                                           unsigned char *addr,
385f7df2e56Smrg                                           short len,
386f7df2e56Smrg                                           void *closure),
387f7df2e56Smrg                    void *closure);
388f7df2e56Smrg
389f7df2e56Smrgextern _X_EXPORT int
390f7df2e56SmrgRemoveHost(ClientPtr client,
391f7df2e56Smrg           int family,
392f7df2e56Smrg           unsigned length,
393f7df2e56Smrg           void *pAddr);
394f7df2e56Smrg
395f7df2e56Smrgextern _X_EXPORT int
396f7df2e56SmrgGetHosts(void ** /*data */ ,
397f7df2e56Smrg         int * /*pnHosts */ ,
398f7df2e56Smrg         int * /*pLen */ ,
399f7df2e56Smrg         BOOL * /*pEnabled */ );
400f7df2e56Smrg
401f7df2e56Smrgtypedef struct sockaddr *sockaddrPtr;
402f7df2e56Smrg
403f7df2e56Smrgextern _X_EXPORT int
404f7df2e56SmrgInvalidHost(sockaddrPtr /*saddr */ , int /*len */ , ClientPtr client);
40505b261ecSmrg
406637ac9abSmrg#define LCC_UID_SET	(1 << 0)
407637ac9abSmrg#define LCC_GID_SET	(1 << 1)
408637ac9abSmrg#define LCC_PID_SET	(1 << 2)
409637ac9abSmrg#define LCC_ZID_SET	(1 << 3)
410637ac9abSmrg
411637ac9abSmrgtypedef struct {
412f7df2e56Smrg    int fieldsSet;              /* Bit mask of fields set */
413f7df2e56Smrg    int euid;                   /* Effective uid */
414f7df2e56Smrg    int egid;                   /* Primary effective group id */
415f7df2e56Smrg    int nSuppGids;              /* Number of supplementary group ids */
416f7df2e56Smrg    int *pSuppGids;             /* Array of supplementary group ids */
417f7df2e56Smrg    int pid;                    /* Process id */
418f7df2e56Smrg    int zoneid;                 /* Only set on Solaris 10 & later */
419637ac9abSmrg} LocalClientCredRec;
420637ac9abSmrg
421f7df2e56Smrgextern _X_EXPORT int
422f7df2e56SmrgGetLocalClientCreds(ClientPtr, LocalClientCredRec **);
423f7df2e56Smrg
424f7df2e56Smrgextern _X_EXPORT void
425f7df2e56SmrgFreeLocalClientCreds(LocalClientCredRec *);
426f7df2e56Smrg
427f7df2e56Smrgextern _X_EXPORT int
428f7df2e56SmrgChangeAccessControl(ClientPtr /*client */ , int /*fEnabled */ );
429f7df2e56Smrg
430f7df2e56Smrgextern _X_EXPORT int
431f7df2e56SmrgGetClientFd(ClientPtr);
432f7df2e56Smrg
433f7df2e56Smrgextern _X_EXPORT Bool
434f7df2e56SmrgClientIsLocal(ClientPtr client);
435f7df2e56Smrg
436f7df2e56Smrgextern _X_EXPORT int
437f7df2e56SmrgGetAccessControl(void);
438f7df2e56Smrg
439f7df2e56Smrgextern _X_EXPORT void
440f7df2e56SmrgAddLocalHosts(void);
441637ac9abSmrg
442f7df2e56Smrgextern _X_EXPORT void
443f7df2e56SmrgResetHosts(const char *display);
44405b261ecSmrg
445f7df2e56Smrgextern _X_EXPORT void
446f7df2e56SmrgEnableLocalAccess(void);
44705b261ecSmrg
448f7df2e56Smrgextern _X_EXPORT void
449f7df2e56SmrgDisableLocalAccess(void);
45005b261ecSmrg
451f7df2e56Smrgextern _X_EXPORT void
452f7df2e56SmrgEnableLocalHost(void);
45305b261ecSmrg
454f7df2e56Smrgextern _X_EXPORT void
455f7df2e56SmrgDisableLocalHost(void);
45605b261ecSmrg
457f7df2e56Smrg#ifndef NO_LOCAL_CLIENT_CRED
458f7df2e56Smrgextern _X_EXPORT void
459f7df2e56SmrgEnableLocalUser(void);
46005b261ecSmrg
461f7df2e56Smrgextern _X_EXPORT void
462f7df2e56SmrgDisableLocalUser(void);
46305b261ecSmrg
464f7df2e56Smrgextern _X_EXPORT void
465f7df2e56SmrgLocalAccessScopeUser(void);
466f7df2e56Smrg#endif
467f7df2e56Smrg
468f7df2e56Smrgextern _X_EXPORT void
469f7df2e56SmrgAccessUsingXdmcp(void);
47005b261ecSmrg
471f7df2e56Smrgextern _X_EXPORT void
472f7df2e56SmrgDefineSelf(int /*fd */ );
47305b261ecSmrg
4747e31ba66Smrg#ifdef XDMCP
475f7df2e56Smrgextern _X_EXPORT void
476f7df2e56SmrgAugmentSelf(void *from, int len);
47705b261ecSmrg
478f7df2e56Smrgextern _X_EXPORT void
479f7df2e56SmrgRegisterAuthorizations(void);
4804202a189Smrg#endif
48105b261ecSmrg
482f7df2e56Smrgextern _X_EXPORT void
483f7df2e56SmrgInitAuthorization(const char * /*filename */ );
48405b261ecSmrg
4854202a189Smrg/* extern int LoadAuthorization(void); */
48605b261ecSmrg
487f7df2e56Smrgextern _X_EXPORT int
488f7df2e56SmrgAuthorizationFromID(XID id,
489f7df2e56Smrg                    unsigned short *name_lenp,
490f7df2e56Smrg                    const char **namep,
491f7df2e56Smrg                    unsigned short *data_lenp, char **datap);
492f7df2e56Smrg
493f7df2e56Smrgextern _X_EXPORT XID
494f7df2e56SmrgCheckAuthorization(unsigned int /*namelength */ ,
495f7df2e56Smrg                   const char * /*name */ ,
496f7df2e56Smrg                   unsigned int /*datalength */ ,
497f7df2e56Smrg                   const char * /*data */ ,
498f7df2e56Smrg                   ClientPtr /*client */ ,
499f7df2e56Smrg                   const char **        /*reason */
500f7df2e56Smrg    );
501f7df2e56Smrg
502f7df2e56Smrgextern _X_EXPORT void
503f7df2e56SmrgResetAuthorization(void);
504f7df2e56Smrg
505f7df2e56Smrgextern _X_EXPORT int
506f7df2e56SmrgRemoveAuthorization(unsigned short name_length,
507f7df2e56Smrg                    const char *name,
508f7df2e56Smrg                    unsigned short data_length, const char *data);
509f7df2e56Smrg
510f7df2e56Smrgextern _X_EXPORT int
511f7df2e56SmrgAddAuthorization(unsigned int /*name_length */ ,
512f7df2e56Smrg                 const char * /*name */ ,
513f7df2e56Smrg                 unsigned int /*data_length */ ,
514f7df2e56Smrg                 char * /*data */ );
51505b261ecSmrg
5164202a189Smrg#ifdef XCSECURITY
517f7df2e56Smrgextern _X_EXPORT XID
518f7df2e56SmrgGenerateAuthorization(unsigned int /* name_length */ ,
519f7df2e56Smrg                      const char * /* name */ ,
520f7df2e56Smrg                      unsigned int /* data_length */ ,
521f7df2e56Smrg                      const char * /* data */ ,
522f7df2e56Smrg                      unsigned int * /* data_length_return */ ,
523f7df2e56Smrg                      char ** /* data_return */ );
5244202a189Smrg#endif
52505b261ecSmrg
526f7df2e56Smrgextern _X_EXPORT int
527f7df2e56SmrgddxProcessArgument(int /*argc */ , char * /*argv */ [], int /*i */ );
52805b261ecSmrg
5295a112b11Smrg#define CHECK_FOR_REQUIRED_ARGUMENTS(num)  \
5305a112b11Smrg    do if (((i + num) >= argc) || (!argv[i + num])) {                   \
5315a112b11Smrg        UseMsg();                                                       \
5325a112b11Smrg        FatalError("Required argument to %s not specified\n", argv[i]); \
5335a112b11Smrg    } while (0)
5345a112b11Smrg
5355a112b11Smrg
536f7df2e56Smrgextern _X_EXPORT void
537f7df2e56SmrgddxUseMsg(void);
53805b261ecSmrg
53905b261ecSmrg/* stuff for ReplyCallback */
5404202a189Smrgextern _X_EXPORT CallbackListPtr ReplyCallback;
54105b261ecSmrgtypedef struct {
54205b261ecSmrg    ClientPtr client;
543637ac9abSmrg    const void *replyData;
544f7df2e56Smrg    unsigned long dataLenBytes; /* actual bytes from replyData + pad bytes */
54505b261ecSmrg    unsigned long bytesRemaining;
54605b261ecSmrg    Bool startOfReply;
547f7df2e56Smrg    unsigned long padBytes;     /* pad bytes from zeroed array */
54805b261ecSmrg} ReplyInfoRec;
54905b261ecSmrg
55005b261ecSmrg/* stuff for FlushCallback */
5514202a189Smrgextern _X_EXPORT CallbackListPtr FlushCallback;
55205b261ecSmrg
553f7df2e56Smrgenum ExitCode {
554f7df2e56Smrg    EXIT_NO_ERROR = 0,
555f7df2e56Smrg    EXIT_ERR_ABORT = 1,
556f7df2e56Smrg    EXIT_ERR_CONFIGURE = 2,
557f7df2e56Smrg    EXIT_ERR_DRIVERS = 3,
558f7df2e56Smrg};
559f7df2e56Smrg
560f7df2e56Smrgextern _X_EXPORT void
561f7df2e56SmrgddxGiveUp(enum ExitCode error);
562806e81e9Smrgextern _X_EXPORT void
563806e81e9SmrgddxInputThreadInit(void);
564f7df2e56Smrgextern _X_EXPORT int
565f7df2e56SmrgTimeSinceLastInputEvent(void);
566f7df2e56Smrg
567f7df2e56Smrg/* Function fallbacks provided by AC_REPLACE_FUNCS in configure.ac */
568f7df2e56Smrg
569f7df2e56Smrg#ifndef HAVE_REALLOCARRAY
570f7df2e56Smrg#define reallocarray xreallocarray
571f7df2e56Smrgextern _X_EXPORT void *
572f7df2e56Smrgreallocarray(void *optr, size_t nmemb, size_t size);
573f7df2e56Smrg#endif
57405b261ecSmrg
575f7df2e56Smrg#ifndef HAVE_STRCASECMP
576637ac9abSmrg#define strcasecmp xstrcasecmp
577f7df2e56Smrgextern _X_EXPORT int
578f7df2e56Smrgxstrcasecmp(const char *s1, const char *s2);
579637ac9abSmrg#endif
580637ac9abSmrg
581f7df2e56Smrg#ifndef HAVE_STRNCASECMP
582637ac9abSmrg#define strncasecmp xstrncasecmp
583f7df2e56Smrgextern _X_EXPORT int
584f7df2e56Smrgxstrncasecmp(const char *s1, const char *s2, size_t n);
585637ac9abSmrg#endif
586637ac9abSmrg
587f7df2e56Smrg#ifndef HAVE_STRCASESTR
588637ac9abSmrg#define strcasestr xstrcasestr
589f7df2e56Smrgextern _X_EXPORT char *
590f7df2e56Smrgxstrcasestr(const char *s, const char *find);
591637ac9abSmrg#endif
592637ac9abSmrg
593f7df2e56Smrg#ifndef HAVE_STRLCPY
594f7df2e56Smrgextern _X_EXPORT size_t
595f7df2e56Smrgstrlcpy(char *dst, const char *src, size_t siz);
596f7df2e56Smrgextern _X_EXPORT size_t
597f7df2e56Smrgstrlcat(char *dst, const char *src, size_t siz);
598f7df2e56Smrg#endif
599f7df2e56Smrg
600f7df2e56Smrg#ifndef HAVE_STRNDUP
601f7df2e56Smrgextern _X_EXPORT char *
602f7df2e56Smrgstrndup(const char *str, size_t n);
603637ac9abSmrg#endif
604637ac9abSmrg
6058199d687Smrg#ifndef HAVE_TIMINGSAFE_MEMCMP
6068199d687Smrgextern _X_EXPORT int
6078199d687Smrgtimingsafe_memcmp(const void *b1, const void *b2, size_t len);
6088199d687Smrg#endif
6098199d687Smrg
61005b261ecSmrg/* Logging. */
61105b261ecSmrgtypedef enum _LogParameter {
61205b261ecSmrg    XLOG_FLUSH,
61305b261ecSmrg    XLOG_SYNC,
61405b261ecSmrg    XLOG_VERBOSITY,
61505b261ecSmrg    XLOG_FILE_VERBOSITY
61605b261ecSmrg} LogParameter;
61705b261ecSmrg
61805b261ecSmrg/* Flags for log messages. */
61905b261ecSmrgtypedef enum {
620f7df2e56Smrg    X_PROBED,                   /* Value was probed */
621f7df2e56Smrg    X_CONFIG,                   /* Value was given in the config file */
622f7df2e56Smrg    X_DEFAULT,                  /* Value is a default */
623f7df2e56Smrg    X_CMDLINE,                  /* Value was given on the command line */
624f7df2e56Smrg    X_NOTICE,                   /* Notice */
625f7df2e56Smrg    X_ERROR,                    /* Error message */
626f7df2e56Smrg    X_WARNING,                  /* Warning message */
627f7df2e56Smrg    X_INFO,                     /* Informational message */
628f7df2e56Smrg    X_NONE,                     /* No prefix */
629f7df2e56Smrg    X_NOT_IMPLEMENTED,          /* Not implemented */
630f7df2e56Smrg    X_DEBUG,                    /* Debug message */
631f7df2e56Smrg    X_UNKNOWN = -1              /* unknown -- this must always be last */
63205b261ecSmrg} MessageType;
63305b261ecSmrg
634f7df2e56Smrgextern _X_EXPORT const char *
635f7df2e56SmrgLogInit(const char *fname, const char *backup);
636f7df2e56Smrgextern void
637f7df2e56SmrgLogSetDisplay(void);
638f7df2e56Smrgextern _X_EXPORT void
639f7df2e56SmrgLogClose(enum ExitCode error);
640f7df2e56Smrgextern _X_EXPORT Bool
641f7df2e56SmrgLogSetParameter(LogParameter param, int value);
642f7df2e56Smrgextern _X_EXPORT void
643f7df2e56SmrgLogVWrite(int verb, const char *f, va_list args)
644f7df2e56Smrg_X_ATTRIBUTE_PRINTF(2, 0);
645f7df2e56Smrgextern _X_EXPORT void
646f7df2e56SmrgLogWrite(int verb, const char *f, ...)
647f7df2e56Smrg_X_ATTRIBUTE_PRINTF(2, 3);
648f7df2e56Smrgextern _X_EXPORT void
649f7df2e56SmrgLogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
650f7df2e56Smrg_X_ATTRIBUTE_PRINTF(3, 0);
651f7df2e56Smrgextern _X_EXPORT void
652f7df2e56SmrgLogMessageVerb(MessageType type, int verb, const char *format, ...)
653f7df2e56Smrg_X_ATTRIBUTE_PRINTF(3, 4);
654f7df2e56Smrgextern _X_EXPORT void
655f7df2e56SmrgLogMessage(MessageType type, const char *format, ...)
656f7df2e56Smrg_X_ATTRIBUTE_PRINTF(2, 3);
657f7df2e56Smrgextern _X_EXPORT void
658f7df2e56SmrgLogMessageVerbSigSafe(MessageType type, int verb, const char *format, ...)
659f7df2e56Smrg_X_ATTRIBUTE_PRINTF(3, 4);
660f7df2e56Smrgextern _X_EXPORT void
661f7df2e56SmrgLogVMessageVerbSigSafe(MessageType type, int verb, const char *format, va_list args)
662f7df2e56Smrg_X_ATTRIBUTE_PRINTF(3, 0);
663f7df2e56Smrg
664f7df2e56Smrgextern _X_EXPORT void
665f7df2e56SmrgLogVHdrMessageVerb(MessageType type, int verb,
666f7df2e56Smrg                   const char *msg_format, va_list msg_args,
667f7df2e56Smrg                   const char *hdr_format, va_list hdr_args)
668f7df2e56Smrg_X_ATTRIBUTE_PRINTF(3, 0)
669f7df2e56Smrg_X_ATTRIBUTE_PRINTF(5, 0);
670f7df2e56Smrgextern _X_EXPORT void
671f7df2e56SmrgLogHdrMessageVerb(MessageType type, int verb,
672f7df2e56Smrg                  const char *msg_format, va_list msg_args,
673f7df2e56Smrg                  const char *hdr_format, ...)
674f7df2e56Smrg_X_ATTRIBUTE_PRINTF(3, 0)
675f7df2e56Smrg_X_ATTRIBUTE_PRINTF(5, 6);
676f7df2e56Smrgextern _X_EXPORT void
677f7df2e56SmrgLogHdrMessage(MessageType type, const char *msg_format,
678f7df2e56Smrg              va_list msg_args, const char *hdr_format, ...)
679f7df2e56Smrg_X_ATTRIBUTE_PRINTF(2, 0)
680f7df2e56Smrg_X_ATTRIBUTE_PRINTF(4, 5);
681f7df2e56Smrg
682f7df2e56Smrgextern _X_EXPORT void
683f7df2e56SmrgFreeAuditTimer(void);
684f7df2e56Smrgextern _X_EXPORT void
685f7df2e56SmrgAuditF(const char *f, ...)
686f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 2);
687f7df2e56Smrgextern _X_EXPORT void
688f7df2e56SmrgVAuditF(const char *f, va_list args)
689f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0);
690f7df2e56Smrgextern _X_EXPORT void
691f7df2e56SmrgFatalError(const char *f, ...)
692f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 2)
693f7df2e56Smrg    _X_NORETURN;
69405b261ecSmrg
69505b261ecSmrg#ifdef DEBUG
69605b261ecSmrg#define DebugF ErrorF
69705b261ecSmrg#else
698f7df2e56Smrg#define DebugF(...)             /* */
69905b261ecSmrg#endif
70005b261ecSmrg
701f7df2e56Smrgextern _X_EXPORT void
702f7df2e56SmrgVErrorF(const char *f, va_list args)
703f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0);
704f7df2e56Smrgextern _X_EXPORT void
705f7df2e56SmrgErrorF(const char *f, ...)
706f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 2);
707f7df2e56Smrgextern _X_EXPORT void
708f7df2e56SmrgVErrorFSigSafe(const char *f, va_list args)
709f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 0);
710f7df2e56Smrgextern _X_EXPORT void
711f7df2e56SmrgErrorFSigSafe(const char *f, ...)
712f7df2e56Smrg_X_ATTRIBUTE_PRINTF(1, 2);
713f7df2e56Smrgextern _X_EXPORT void
714f7df2e56SmrgLogPrintMarkers(void);
715f7df2e56Smrg
716f7df2e56Smrgextern _X_EXPORT void
717f7df2e56Smrgxorg_backtrace(void);
718f7df2e56Smrg
719f7df2e56Smrgextern _X_EXPORT int
720f7df2e56Smrgos_move_fd(int fd);
721f7df2e56Smrg
7227e31ba66Smrg#include <signal.h>
7237e31ba66Smrg
7245a112b11Smrg#if defined(WIN32) && !defined(__CYGWIN__)
7255a112b11Smrgtypedef _sigset_t sigset_t;
7265a112b11Smrg#endif
7275a112b11Smrg
7287e31ba66Smrgextern _X_EXPORT int
7297e31ba66Smrgxthread_sigmask(int how, const sigset_t *set, sigset_t *oldest);
7307e31ba66Smrg
731f7df2e56Smrg#endif                          /* OS_H */
732