[stsf-commit] stsf/STFontServer/src handler.c, 1.3, 1.4 handler.h,
1.1.1.1, 1.2 makefile, 1.6, 1.7 saverestore.c, 1.3,
1.4 stfs-door.c, 1.4, 1.5 stfs.h, 1.2, 1.3
Alexander Gelfenbain
stsf-commit at pdx.freedesktop.org
Mon May 24 19:47:27 PDT 2004
- Previous message: [stsf-commit] stsf/STFontServer/loader stfsloader.c,1.1.1.1,1.2
- Next message: [stsf-commit]
stsf/interface VERSION, NONE, 1.1 genversion.py, NONE,
1.1 stprivate.h, NONE, 1.1 fontserver.h, 1.3, 1.4 makefile,
1.5, 1.6 sttypes.tmpl, 1.6, 1.7 genproto.py, 1.3,
NONE genstsf.py, 1.1.1.1, NONE interface.xml, 1.5,
NONE protocol.xml, 1.5, NONE stprivate.tmpl, 1.2, NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: adg
Index: handler.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/handler.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/handler.c 22 Apr 2004 20:56:32 -0000 1.3
+++ b/handler.c 25 May 2004 02:47:24 -0000 1.4
@@ -71,9 +71,9 @@
#include <alloca.h>
#endif
-#include "conn.h"
+#include "fscomm.h"
#include "fontserver.h"
-#include "stfsproto.h"
+/* #include "stfsproto.h" */
#include "st.h"
#include "inlines.h"
[...1335 lines suppressed...]
free(offsets);
}
}
- return HR_OK;
+ return ret;
default:
- {
- if(opcode & 1){ /* Protocol defines odd opcode is *_R packet */
- ErrorStr("%s: wrong role opcode %X.", modname, opcode);
- } else {
- ErrorStr("%s: wrong opcode %X.", modname, opcode);
- }
-
- sendprotoerror("protocol error", fd, STFS_PROTOERROR, pbuf);
- return HR_OPCODE;
- }
+ return ST_PROTO_ERROR;
}
}
Index: handler.h
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/handler.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/handler.h 26 Mar 2004 19:19:56 -0000 1.1.1.1
+++ b/handler.h 25 May 2004 02:47:24 -0000 1.2
@@ -49,24 +49,17 @@
#ifndef __HANDLER_H
#define __HANDLER_H
-typedef enum {
- HR_OPCODE = -2, /* unrecognized opcode */
- HR_MEMORY = -1, /* memory allocation error */
- HR_OK = 0, /* no error */
- HR_CLOSE = 1, /* STFS_CLOSE request received */
- HR_CONNECT = 2 /* STFS_CONNECT request received */
-} FSHRStatus;
-
+#include "fscomm.h"
+
+
+STStatus FSHandleRequest(FontServer fs,
+ intptr_t ckey,
+ intptr_t cdata,
+ STFSProtoOpcode *opcode, /* on exit contains reply */
+ byte *p, /* protocol shared memory */
+ uint32_t s); /* size of the protocol shared memory */
+
-FSHRStatus FSHandleRequest(FontServer fs,
- intptr_t ckey,
- intptr_t cdata,
- int fd,
- STFSProtoOpcode opcode,
- uint16_t packlen,
- byte *pbuf,
- uint32_t pbufsize /*,
- byte *bitmap */);
#endif /* __HANDLER_H */
Index: makefile
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/makefile 22 Apr 2004 20:56:32 -0000 1.6
+++ b/makefile 25 May 2004 02:47:24 -0000 1.7
@@ -82,7 +82,7 @@
PROTOTEST_SRCS= prototest-door.c
PROTOTEST_OBJS=$(PROTOTEST_SRCS:%.c=%.o)
FONTSERVER_BINARY= stfontserverd
- PROTOTEST_BINARY= prototest
+# PROTOTEST_BINARY= prototest
DAEMON_SRCS= $(LIBSTFONTSERVER_SRCS) stfs-door.c handler.c
else
PROTOTEST_SRCS= prototest.c
Index: saverestore.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/saverestore.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/saverestore.c 22 Apr 2004 20:56:32 -0000 1.3
+++ b/saverestore.c 25 May 2004 02:47:24 -0000 1.4
@@ -2733,11 +2733,11 @@
int fd;
if (stat(filename, &st) != 0) {
- ErrorStr("RestoreFontEnumerator: file not found %s.", filename);
+ ErrorStr("%s: file not found %s.", __func__, filename);
return ST_FILEIO;
}
if ((fd = open(filename, O_RDONLY)) == -1) {
- ErrorStr("SaveFontEnumerator: Error accessing file %s.", filename);
+ ErrorStr("%s: Error accessing file %s.", __func__, filename);
return ST_FILEIO;
}
@@ -2754,7 +2754,7 @@
lastFontID, lastBitmapFontID);
if (header == 0) {
- ErrorStr("FontEnumeratorHeaderRestore: error.");
+ ErrorStr("%s: error.", __func__);
ret = ST_INTERNAL_ERROR;
goto cleanup;
}
Index: stfs-door.c
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/stfs-door.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/stfs-door.c 22 Apr 2004 20:56:32 -0000 1.4
+++ b/stfs-door.c 25 May 2004 02:47:24 -0000 1.5
@@ -69,19 +69,14 @@
#include <signal.h>
#include <door.h>
#include <errno.h>
-
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
+#include <dirent.h>
#if DAEMONIZE
#include <syslog.h>
#include <stdarg.h>
#endif
-#include "conn.h"
#include "fontserver.h"
-#include "stfsproto.h"
#include "st.h"
#include "inlines.h"
@@ -94,62 +89,6 @@
const char *modname = "stfontserverd";
static FontServer fs = NULL;
-#if 0
-
-struct {
- pthread_mutex_t lock;
- pthread_cond_t cond;
- isready;
-} fslock = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, FALSE};
-
-#endif
-
-
-#if 0
-long _stmaxsession = 0 ;
-long _stcurrentmaxsession = 0 ;
-long _stnumsessions = 0 ;
-#endif
-
-/*
- * sendreply() and sendprotoerror() are called from handler.c
- * sendreply() assumes that there are four bytes in front of the
- * data buffer "void *data" to store the packet header
- *
- *
- *
- */
-
-
-/* XXX add an error message to syslog */
-void sendprotoerror(const char *msg, int iafd, int errcode, void *pbuf)
-{
- // uint16_t buf[STFSPHEADER + 2]; /* array of 4 uint16_t's */
-
- assert(pbuf != NULL);
-
- ErrorStr("sendproterror: errcode: %d", errcode);
-
- ((uint16_t *)pbuf)[OPCODE-2] = STFS_PROTOERROR;
- ((uint16_t *)pbuf)[PACLEN-2] = 1;
- ((uint16_t *)pbuf)[0] = errcode;
-
- if (msg != NULL) {
- ErrorStr("%s: sendprotoerror: %s.", modname, msg);
- }
- /* door_return((char *) buf, 8, NULL, 0); */
-}
-
-void sendreply(int iafd, STFSProtoOpcode opcode, int nbytes, void *pbuf)
-{
- // uint16_t header[STFSPHEADER];
- assert(pbuf != NULL);
-
- DebugStr(9, "sendreply: %s, nbytes: %d.", ProtoOpcodeName(opcode), nbytes);
-
- ((uint16_t *) pbuf)[OPCODE-2] = opcode;
- ((uint16_t *) pbuf)[PACLEN-2] = B2C32U(nbytes);
-}
fsclient *fsclient_allocate(uint_t euid, uint64_t cid) {
fsclient *fsc = calloc(1, sizeof(fsclient));
@@ -159,6 +98,7 @@
}
fsc->euid = euid;
+ fsc->shmfd = -1;
fsc->cid = cid;
fsc->nthr = 0;
@@ -182,10 +122,15 @@
pthread_mutex_destroy(&fsc->lock);
pthread_cond_destroy(&fsc->cond);
+#if 0
if (fsc->shmemfile != NULL) {
unlink(fsc->shmemfile);
free(fsc->shmemfile);
}
+#endif
+ if (fsc->shmfd != -1) {
+ close(fsc->shmfd);
+ }
munmap(fsc->shmaddr, fsc->shmlen); /* that's what releaseshmem() in handler.c used to do */
DebugStr(1, "%s: close(%d)", __func__, fsc->fd);
@@ -194,19 +139,103 @@
}
}
+/* filename should point to the buffer of PATH_MAX bytes */
+static STStatus createshmem(uid_t cuid, int *retfd, void **addr, uint32_t *len)
+{
+ struct stat st;
+ int fd = -1;
+ void *pa = NULL;
+ STStatus ret;
+ int k, l;
+ SharedMemoryHeader *hdr;
+ char filename[PATH_MAX];
+ *retfd = -1;
+
+ if (seteuid((uid_t) 0) == -1) {
+ ErrorStr("Error setting root euid");
+ ret = ST_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if ((stat(SHMEM_DIR, &st) == -1) &&
+ (CreateDir(SHMEM_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ||
+ chown(SHMEM_DIR, STFS_UID, STFS_GID))) {
+ ErrorStr("Error creating STSF shared memory directory: %s.", SHMEM_DIR);
+ ret = ST_FILEIO;
+ goto cleanup;
+ }
+
+ strlcpy(filename, SHMEM_DIR, PATH_MAX);
+ strlcat(filename, "/", PATH_MAX);
+ strlcat(filename, SHMEM_PATTERN, PATH_MAX);
+
+ if ((fd = mkstemp(filename)) == -1 ||
+ ftruncate(fd, SHMEM_SIZE) == -1 ||
+ (pa = mmap((void *) 0, SHMEM_SIZE, (PROT_READ | PROT_WRITE), (MAP_SHARED | MAP_NORESERVE), fd, 0)) == MAP_FAILED) {
+ ErrorStr("Error creating STSF shared memory file: %s.", filename);
+ ret = ST_FILEIO;
+ unlink(filename);
+ seteuid(STFS_UID);
+ goto cleanup;
+ }
+ unlink(filename);
+
+
+ k = fchown(fd, cuid, STFS_GID); /* shared memory owner is user and group is daemon */
+ l = fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* 0660 */
+
+ if (seteuid(STFS_UID) == -1) {
+ ErrorStr("Error setting euid: %d.", STFS_UID);
+ ret = ST_INTERNAL_ERROR;
+ goto cleanup;
+ }
+
+ if (k == -1 || l == -1) {
+ ErrorStr("Error setting the shared memory owner.");
+ ret = ST_FILEIO;
+ goto cleanup;
+ }
+
+ // close(fd);
+ *retfd = fd;
+
+ *addr = pa;
+ *len = SHMEM_SIZE;
+
+ /* initialize the shared memory layout */
+ hdr = (SharedMemoryHeader *) pa;
+ hdr->cid = 0; /* To be initialized by the client */
+ hdr->size = SHMEM_SIZE;
+ hdr->sc_offset = sizeof(SharedMemoryHeader);
+ hdr->sc_size = SHMEM_SIZE - SHMEM_PROTO - sizeof(SharedMemoryHeader);
+ hdr->proto_offset = sizeof(SharedMemoryHeader) + hdr->sc_size;
+ hdr->proto_size = SHMEM_PROTO;
+
+ SharedCacheInit((byte *) pa + hdr->sc_offset, hdr->sc_size);
+
+ return ST_OK;
+
+
+cleanup:
+ if (fd != -1) close(fd);
+ if (pa != NULL) munmap (pa, SHMEM_SIZE);
+ // *filename = '\0';
+ *addr = NULL;
+ *len = 0;
+ return ret;
+}
static void proto_handler(void *cookie, char *argp, size_t argsize, door_desc_t *dp, uint_t ndesc)
{
- uint8_t opcode, reply;
- uint16_t packlen;
- byte *pbuf;
- FSHRStatus handler_status;
STBoolean connected = FALSE; /* CONNECT received */
- uint32_t bytelen;
- uint32_t pbufsize = PROTO_BUFSIZE;
door_cred_t dcred;
intptr_t ckey;
fsclient *fsc = NULL;
+ DoorRequestIn *ri;
+ DoorRequestOut ro;
+ door_desc_t desc;
+ door_desc_t *pdesc = NULL;
+ int ret_ndesc = 0;
#ifdef STSF_DEBUG
if (DebugLevel > 8) {
@@ -224,16 +253,13 @@
* are valid from that client
*/
if ((fsc = (fsclient *) FSGetClientData(fs, ckey)) == NULL && argp != DOOR_UNREF_DATA) {
- uint16_t buf[STFSPHEADER+2];
DebugStr(1, "%s: pthread: %d, unknown client, ckey: %d", __func__, pthread_self(), ckey);
- sendprotoerror("Unknown client", 0, ST_MEMORY, buf+STFSPHEADER);
- DebugStr(1, "%s: pthread: %d, BEFORE door_return(), sizeof(buf): %d", __func__, pthread_self(), sizeof(buf));
- if (door_return((char *) buf, sizeof(buf), NULL, 0) == -1) {
- DebugStr(1, "%s: door_return() returned -1 [A] len: %d", __func__, sizeof(buf));
+ ro.cid = -1;
+ ro.ret = ST_INTERNAL_ERROR;
+ if (door_return((char *) &ro, sizeof ro, NULL, 0) == -1) {
perror("door_return");
if (errno == E2BIG) {
if (door_return(NULL, 0, NULL, 0) == -1) {
- DebugStr(1, "%s: door_return() returned -1 [AA] len: %d", __func__, sizeof(buf));
perror("door_return");
}
}
@@ -283,93 +309,85 @@
door_cred(&dcred); /* should never fail */
+ ri = (DoorRequestIn *) argp;
+ ro.cid = fsc->cid;
+ ro.ret = ST_OK;
- if ((pbuf = alloca(4+PROTO_BUFSIZE)) == NULL) {
- uint16_t buf[STFSPHEADER + 2]; /* array of 4 uint16_t's */
- sendprotoerror("alloca(): insufficient memory", 0, ST_MEMORY, buf + STFSPHEADER);
-
- pthread_mutex_lock(&fsc->lock);
- fsc->nthr--;
- DebugStr(1,"%s: decrementing nthr[B]: pthread: %d, nthr: %d, ckey: %d.", __func__, pthread_self(), fsc->nthr, ckey);
- pthread_mutex_unlock(&fsc->lock);
- pthread_cond_signal(&fsc->cond);
- if (door_return((char*)buf, sizeof(buf), NULL, 0) == -1) {
- DebugStr(1, "%s: door_return() returned -1 [C] len: %d", __func__, sizeof(buf));
- perror("door_return");
- return;
- }
- }
-
- memcpy(pbuf, argp, argsize);
-
- opcode = ((uint16_t *) argp)[OPCODEINDEX] & OPCODEMASK;
- reply = opcode + 1; /* XXX Valid for all protocol requests except STFS_CONNECT */
- packlen = ((uint16_t *) argp)[PACKLENINDEX];
- bytelen = packlen << 2;
-
- DebugStr(8, "%s: J", __func__);
- FSLock(fs);
- DebugStr(8, "%s: K", __func__);
- handler_status = FSHandleRequest(fs, ckey, (intptr_t) fsc, 0, opcode, packlen, pbuf+4, pbufsize);
- DebugStr(8, "%s: L", __func__);
- FSUnlock(fs);
- DebugStr(8, "%s: M", __func__);
-
- switch (handler_status) {
- case HR_OPCODE:
- ErrorStr("%s: protocol handler received unrecognized opcode: %s (%x).",
- modname, ProtoOpcodeName(opcode), opcode);
- break;
-
- case HR_MEMORY:
- ErrorStr("%s: alloca failed in the protocol handler.", modname);
+ switch (ri->state) {
+ case CONNECT:
+ if (fsc->state != CONNECT) {
+ DebugStr(1, "%s: ri->state: %d, fsc->state: %d. Resetting connection.", __func__, ri->state, fsc->state);
+ if (fsc->shmfd != -1) {
+ close(fsc->shmfd);
+ fsc->shmfd = -1;
+ }
+ }
+ DebugStr(2, "%s: ckey: %d -CONNECT-, payloadsize: %d", __func__, ckey, ri->x.c.payloadsize);
+ if ((ro.ret = createshmem(fsc->euid, &fsc->shmfd, &fsc->shmaddr, &fsc->shmlen)) != ST_OK) {
+ ErrorStr("%s: error '%s' creating shared memory.", __func__, ErrorCodeName(ro.ret));
+ } else {
+ ro.x.c.memsize = fsc->shmlen;
+ fsc->state = VERIFY;
+ ret_ndesc = 1;
+ desc.d_data.d_desc.d_descriptor = fsc->shmfd;
+ pdesc = &desc;
+ fsc->psize = ri->x.c.payloadsize;
+ }
break;
- case HR_OK:
+ case VERIFY:
+ if (fsc->state != VERIFY) {
+ ErrorStr("%s: ri->state: %d, fsc->state: %d. Protocol Error", __func__, ri->state, fsc->state);
+ ro.ret = ST_PROTO_ERROR;
+ } else {
+ close(fsc->shmfd);
+ fsc->shmfd = -1;
+ if (*(uint64_t *) fsc->shmaddr != fsc->cid) {
+ ro.ret = ST_FILEIO;
+ } else {
+ fsc->state = PROTOCOL;
+ }
+ }
break;
- case HR_CLOSE:
- DebugStr(1, "%s: deallocating the client after receiving HR_CLOSE, nthr: %d", __func__, fsc->nthr);
- // close(fsc->fd); /* Close the client's door */
-
- DebugStr(1, "%s: [D1] nthr: %d", __func__, fsc->nthr);
+ case PROTOCOL:
+ if (fsc->state != PROTOCOL) {
+ ErrorStr("%s: ri->state: %d, fsc->state: %d. Protocol Error", __func__, ri->state, fsc->state);
+ ro.ret = ST_PROTO_ERROR;
+ } else {
+ SharedMemoryHeader *hdr = (SharedMemoryHeader *) fsc->shmaddr;
- pthread_mutex_lock(&fsc->lock);
- while (fsc->nthr > 1) {
- pthread_cond_wait(&fsc->cond, &fsc->lock);
- }
- DebugStr(1, "%s: [D2] nthr: %d", __func__, fsc->nthr);
- FSDeleteClient(fs, ckey);
- fsc->nthr--;
- DebugStr(1, "%s: [D3] nthr: %d", __func__, fsc->nthr);
- DebugStr(1,"%s: decrementing nthr[C]: pthread: %d, nthr: %d, ckey: %d.", __func__, pthread_self(), fsc->nthr, ckey);
- pthread_mutex_unlock(&fsc->lock);
+ ro.x.p.opcode = ri->x.p.opcode;
+ ro.ret = FSHandleRequest(fs, ckey, (intptr_t) fsc, &ro.x.p.opcode,
+ (byte *) fsc->shmaddr + hdr->proto_offset, hdr->proto_size);
- fsclient_destroy(fsc);
- if (door_return((char*) pbuf, 4 + ((uint16_t *) pbuf)[PACLEN] * 4, NULL, 0) == -1) {
- DebugStr(1, "%s: door_return() returned -1 [D], len: %d", __func__, 4 + ((uint16_t *) pbuf)[PACLEN] * 4);
- perror("door_return");
- return;
- }
+ if (ro.x.p.opcode == FS_CLOSE_OUT) {
+ DebugStr(1, "%s: deallocating the client after receiving HR_CLOSE, nthr: %d", __func__, fsc->nthr);
+ // close(fsc->fd); /* Close the client's door */
- break;
+ DebugStr(1, "%s: [D1] nthr: %d", __func__, fsc->nthr);
+
+ pthread_mutex_lock(&fsc->lock);
+ while (fsc->nthr > 1) {
+ pthread_cond_wait(&fsc->cond, &fsc->lock);
+ }
+ DebugStr(1, "%s: [D2] nthr: %d", __func__, fsc->nthr);
+ FSDeleteClient(fs, ckey);
+ fsc->nthr--;
+ DebugStr(1, "%s: [D3] nthr: %d", __func__, fsc->nthr);
+ DebugStr(1,"%s: decrementing nthr[C]: pthread: %d, nthr: %d, ckey: %d.", __func__, pthread_self(), fsc->nthr, ckey);
+ pthread_mutex_unlock(&fsc->lock);
- case HR_CONNECT:
- if (!connected) {
- connected = TRUE;
- } else {
- ErrorStr("%s: already connected.", modname);
+ fsclient_destroy(fsc);
+ goto doorret;
+ }
}
+
+ break;
+ default:
+ ro.ret = ST_PROTO_ERROR;
}
-#ifdef STSF_DEBUG
- if (DebugLevel > 8) {
- fprintf(DebugFile, "proto_handler: sending back:\n");
- HexDump(pbuf, 4 + ((uint16_t *) pbuf)[PACLEN] * 4);
- }
-#endif
-
-
DebugStr(8, "%s: N", __func__);
pthread_mutex_lock(&fsc->lock);
DebugStr(8, "%s: O", __func__);
@@ -380,8 +398,9 @@
pthread_cond_signal(&fsc->cond);
DebugStr(8, "%s: Q", __func__);
- if (door_return((char*) pbuf, 4 + ((uint16_t *) pbuf)[PACLEN] * 4, NULL, 0) == -1) {
- DebugStr(1, "%s: door_return() returned -1 [E], len: %d", __func__, 4 + ((uint16_t *) pbuf)[PACLEN] * 4);
+doorret:
+
+ if (door_return((char*) &ro, sizeof ro, pdesc, ret_ndesc) == -1) {
perror("door_return");
}
}
@@ -445,6 +464,18 @@
}
+ /* Handle HANDSHAKE_VERIFY */
+ if (in->opcode == HANDSHAKE_VERIFY) {
+ out.ret = ST_OK;
+ out.opcode = HANDSHAKE_VERIFY_REPLY;
+ if (door_return((char *) &out, sizeof(DoorHandshakeOut), NULL, 0) == -1) {
+ DebugStr(1, "%s: door_return() returned -1 [C], len: %d", __func__, sizeof(DoorHandshakeOut));
+ perror("door_return");
+ return;
+ }
+
+ }
+
if ((fsc = fsclient_allocate(dcred.dc_euid, in->cid)) == NULL) {
out.ret = ST_INTERNAL_ERROR;
if (door_return((char *) &out, sizeof(DoorHandshakeOut), NULL, 0) == -1) {
@@ -501,6 +532,38 @@
}
+static void CheckTempDir(char *path, uid_t uid, gid_t gid)
+{
+ DIR *dirp = opendir(path);
+ struct dirent *dp;
+ struct stat st;
+
+ if (!dirp) {
+ if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
+ unlink(path);
+ }
+ return;
+ }
+
+ while(1) {
+ char *cp;
+
+ if ((dp = readdir(dirp)) == NULL) break;
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue;
+ cp = malloc(strlen(path) + strlen(dp->d_name) + 2);
+ strcpy(cp, path); strcat(cp, "/"); strcat(cp, dp->d_name);
+ if (stat(cp, &st) == 0) {
+ if (st.st_uid != uid || st.st_gid != gid) {
+ DelTree(cp);
+ } else if (S_ISDIR(st.st_mode)) {
+ CheckTempDir(cp, uid, gid);
+ }
+ }
+ free(cp);
+ }
+ closedir(dirp);
+ rmdir(path);
+}
static STStatus system_init (FontServer *fs) {
@@ -511,6 +574,9 @@
int dl = 0;
STStatus t;
int fd, fd2;
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat st;
if (debuglevel != NULL) {
dl = atoi(debuglevel);
@@ -559,7 +625,7 @@
#endif
{
/* XXX Need the configure script to provide a default fontpath */
- fontpath="/usr/X11R6/lib/X11/fonts:/usr/openwin/lib/X11/fonts" ;
+ fontpath="/usr/X11R6/lib/X11/fonts:/usr/openwin/lib/X11/fonts:/usr/openwin/lib/locale" ;
ErrorStr("STFONTPATH is not set, defaulting to:\n\t%s", fontpath);
/* return ST_BAD_FONTPATH; */
}
@@ -581,6 +647,12 @@
#endif
}
+ /* Check /var/tmp/stsf presense and permissions before switching UID */
+ DelTree(SHMEM_DIR);
+ DelTree(TEMP_FONT_DIR);
+ CheckTempDir(STSF_TEMPDIR, STFS_UID, STFS_GID);
+
+
setegid(STFS_GID); /* daemon */
seteuid(STFS_UID); /* daemon */
@@ -665,83 +737,6 @@
seteuid(1);
}
-/* filename should point to the buffer of PATH_MAX bytes */
-STStatus createshmem(uid_t cuid, char *filename, void **addr, uint32_t *len)
-{
- struct stat st;
- int fd = -1;
- void *pa = NULL;
- STStatus ret;
- int k, l;
- SharedMemoryHeader *hdr;
-
- if (seteuid((uid_t) 0) == -1) {
- ErrorStr("Error setting root euid");
- ret = ST_INTERNAL_ERROR;
- goto cleanup;
- }
-
- if ((stat(SHMEM_DIR, &st) == -1) &&
- (CreateDir(SHMEM_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) ||
- chown(SHMEM_DIR, STFS_UID, STFS_GID))) {
- ErrorStr("Error creating STSF shared memory directory: %s.", SHMEM_DIR);
- ret = ST_FILEIO;
- goto cleanup;
- }
-
- strlcpy(filename, SHMEM_DIR, PATH_MAX);
- strlcat(filename, "/", PATH_MAX);
- strlcat(filename, SHMEM_PATTERN, PATH_MAX);
-
- if ((fd = mkstemp(filename)) == -1 ||
- ftruncate(fd, SHMEM_SIZE) == -1 ||
- (pa = mmap((void *) 0, SHMEM_SIZE, (PROT_READ | PROT_WRITE), (MAP_SHARED | MAP_NORESERVE), fd, 0)) == MAP_FAILED) {
- ErrorStr("Error creating STSF shared memory file: %s.", filename);
- ret = ST_FILEIO;
- goto cleanup;
- }
-
-
- k = fchown(fd, cuid, STFS_GID); /* shared memory owner is user and group is daemon */
- l = fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* 0660 */
-
- if (seteuid(STFS_UID) == -1) {
- ErrorStr("Error setting euid: %d.", STFS_UID);
- ret = ST_INTERNAL_ERROR;
- goto cleanup;
- }
-
- if (k == -1 || l == -1) {
- ErrorStr("Error setting the shared memory owner.");
- ret = ST_FILEIO;
- goto cleanup;
- }
-
- close(fd);
-
- *addr = pa;
- *len = SHMEM_SIZE;
-
- /* initialize the shared memory layout */
- hdr = (SharedMemoryHeader *) pa;
- hdr->cid = 0; /* To be initialized by the client */
- hdr->size = SHMEM_SIZE;
- hdr->sc_offset = sizeof(SharedMemoryHeader);
- hdr->sc_size = SHMEM_SIZE - sizeof(SharedMemoryHeader);
-
- SharedCacheInit((byte *) pa + hdr->sc_offset, hdr->sc_size);
-
- return ST_OK;
-
-
-cleanup:
- if (fd != -1) close(fd);
- if (pa != NULL) munmap (pa, SHMEM_SIZE);
- *filename = '\0';
- *addr = NULL;
- *len = 0;
- return ret;
-}
int main(int argc, char** argv) {
@@ -810,4 +805,3 @@
return 0;
}
-
Index: stfs.h
===================================================================
RCS file: /cvs/stsf/stsf/STFontServer/src/stfs.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/stfs.h 22 Apr 2004 20:56:32 -0000 1.2
+++ b/stfs.h 25 May 2004 02:47:24 -0000 1.3
@@ -61,12 +61,9 @@
# endif
#endif
-
-
-
typedef struct {
uid_t euid; /* effective user ID of the client */
- char *shmemfile; /* exists between CONNECT and OPEN protocol requests */
+ int shmfd; /* server keeps it open between CONNECT and VERIFY */
void *shmaddr;
size_t shmlen;
uint64_t cid;
@@ -75,6 +72,7 @@
pthread_mutex_t lock;
pthread_cond_t cond;
int nthr; /* number of threads handling this client */
+ FSProtoState state;
} fsclient;
@@ -92,7 +90,7 @@
void sendreply(int iafd, STFSProtoOpcode opcode, int nbytes, void *pbuf);
-STStatus createshmem(uid_t cuid, char *filename, void **addr, uint32_t *len);
+/* STStatus createshmem(uid_t cuid, char *filename, void **addr, uint32_t *len); */
#endif /* __STFS_H */
- Previous message: [stsf-commit] stsf/STFontServer/loader stfsloader.c,1.1.1.1,1.2
- Next message: [stsf-commit]
stsf/interface VERSION, NONE, 1.1 genversion.py, NONE,
1.1 stprivate.h, NONE, 1.1 fontserver.h, 1.3, 1.4 makefile,
1.5, 1.6 sttypes.tmpl, 1.6, 1.7 genproto.py, 1.3,
NONE genstsf.py, 1.1.1.1, NONE interface.xml, 1.5,
NONE protocol.xml, 1.5, NONE stprivate.tmpl, 1.2, NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the stsf-commit
mailing list