[uim-commit] r1506 - in trunk: . replace uim

omote at freedesktop.org omote at freedesktop.org
Fri Sep 16 11:04:09 PDT 2005


Author: omote
Date: 2005-09-16 11:04:07 -0700 (Fri, 16 Sep 2005)
New Revision: 1506

Added:
   trunk/replace/
   trunk/replace/Makefile.am
   trunk/replace/getpeereid.c
   trunk/replace/setenv.c
   trunk/replace/strsep.c
Removed:
   trunk/uim/getpeereid.c
   trunk/uim/setenv.c
   trunk/uim/strsep.c
Modified:
   trunk/
   trunk/Makefile.am
   trunk/configure.ac
   trunk/uim/Makefile.am
   trunk/uim/uim-ipc.c
Log:
 r1514 at minamo:  omote | 2005-09-17 02:52:44 +0900
 * Sources in uim directory which come from outside of uim are put into
   'replace' directory. These sources are existing for the specific OSes
   that does not support certain functions such as setenv(), unsetenv(),
   getpeereid() and etc...
   .
   The purpose of this is to make it clear the origin of the sources - whether
   the source is created by uim originally or got from outside of uim, for
   example NetBSD.
 
 * Makefile.am, configure.ac: Add replace direcotry.
 * replace: New directory.
 * replace/setenv.c, replace/getpeereid.c, replace/strsep.c: moved from uim/.
 * uim/Makefile.am(libuim, uim-module-manager): Link against libreplace.la.
 * uim/uim-ipc.c: Move uim_helper_check_connection_fd from uim/getpeereid.c.
 



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   + 2f05256a-0800-0410-85e3-84fe06922419:/local/uim/trunk:1514

Modified: trunk/Makefile.am
===================================================================
--- trunk/Makefile.am	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/Makefile.am	2005-09-16 18:04:07 UTC (rev 1506)
@@ -1,5 +1,5 @@
 AUTOMAKE_OPTIONS = foreign
-SUBDIRS = m4 doc uim scm gtk qt xim helper po tables test fep examples pixmaps
+SUBDIRS = m4 doc replace uim scm gtk qt xim helper po tables test fep examples pixmaps
 EXTRA_DIST = README.ja INSTALL.ja test.sh.in uim.spec.in \
 	intltool-extract.in intltool-merge.in intltool-update.in \
 	uim.pc.in ChangeLog.old uim.desktop autogen.sh RELEASING

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/configure.ac	2005-09-16 18:04:07 UTC (rev 1506)
@@ -189,7 +189,8 @@
 # Checks for function
 AC_CHECK_FUNCS([cfmakeraw])
 AC_CHECK_FUNCS([wcswidth])
-AC_CHECK_FUNCS(getpeereid asprintf vasprintf vsnprintf setenv unsetenv strsep)
+AC_CHECK_FUNCS(asprintf vasprintf vsnprintf)
+AC_REPLACE_FUNCS(getpeereid strsep setenv unsetenv)
 AC_CHECK_FUNCS(getpid stat mkdir chmod)
 AC_CACHE_CHECK([for C99 vsnprintf], uim_cv_HAVE_C99_VSNPRINTF,[
 AC_TRY_RUN([
@@ -802,6 +803,7 @@
 		 examples/Makefile
 		 examples/uim-custom/Makefile
 		 pixmaps/Makefile
+		 replace/Makefile
 		 uim.pc
 		 uim.desktop
                  ])

Added: trunk/replace/Makefile.am
===================================================================
--- trunk/replace/Makefile.am	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/replace/Makefile.am	2005-09-16 18:04:07 UTC (rev 1506)
@@ -0,0 +1,5 @@
+INCLUDES = -I.. -I$(top_srcdir)/uim -I$(top_srcdir)/intl
+
+noinst_LTLIBRARIES = libreplace.la
+libreplace_la_SOURCES = strsep.c getpeereid.c setenv.c
+#libreplace_a_LIBADD = @LIBOBJS@

Added: trunk/replace/getpeereid.c
===================================================================
--- trunk/replace/getpeereid.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/replace/getpeereid.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2002,2004 Damien Miller <djm at mindrot.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, 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.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/param.h>
+#include "uim.h"
+#include "uim-helper.h"
+
+#if !defined(HAVE_GETPEEREID)
+
+#if defined(SO_PEERCRED)
+int
+getpeereid(int s, uid_t *euid, gid_t *gid)
+{
+	struct ucred cred;
+	socklen_t len = sizeof(cred);
+
+	if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
+		return (-1);
+	*euid = cred.uid;
+	*gid = cred.gid;
+
+	return (0);
+}
+#elif defined(LOCAL_CREDS)	/* NetBSD */
+int
+getpeereid(int s, uid_t *euid, gid_t *gid)
+{
+/* Credentials structure */
+#ifdef __NetBSD__	/* XXX: should use autoconf */
+#define HAVE_STRUCT_SOCKCRED
+#endif
+#if defined(HAVE_STRUCT_CMSGCRED)
+        typedef struct cmsgcred Cred;
+
+#define cruid cmcred_euid
+#define crgid cmcred_groups[0]
+#elif defined(HAVE_STRUCT_FCRED)
+        typedef struct fcred Cred;
+
+#define cruid fc_uid
+#define crgid fc_gid
+#elif defined(HAVE_STRUCT_SOCKCRED)
+        typedef struct sockcred Cred;
+
+#define cruid sc_euid
+#define crgid sc_egid
+#endif
+        Cred *cred;
+
+        /* Compute size without padding */
+        char cmsgmem[CMSG_SPACE(sizeof(Cred))]; /* for NetBSD */
+
+        /* Point to start of first structure */
+        struct cmsghdr *cmsg = (struct cmsghdr *)cmsgmem;
+
+        struct iovec iov;
+        char buf;
+        struct msghdr msg;
+
+        memset(&msg, 0, sizeof(msg));
+        msg.msg_iov = &iov;
+        msg.msg_iovlen = 1;
+        msg.msg_control = (char *)cmsg;
+        msg.msg_controllen = sizeof(cmsgmem);
+        memset(cmsg, 0, sizeof(cmsgmem));
+
+        /*
+         * The one character which is received here is not meaningful; its
+         * purposes is only to make sure that recvmsg() blocks long enough for
+         * the other side to send its credentials.
+         */
+        iov.iov_base = &buf;
+        iov.iov_len = 1;
+
+        if (recvmsg(s, &msg, 0) < 0 ||
+                cmsg->cmsg_len < sizeof(cmsgmem) ||
+                cmsg->cmsg_type != SCM_CREDS)
+        {
+                return -1;
+        }
+
+        cred = (Cred *)CMSG_DATA(cmsg);
+	*euid = cred->cruid;
+	*gid = cred->crgid;
+
+	return 0;
+}
+#else
+int
+getpeereid(int s, uid_t *euid, gid_t *gid)
+{
+	*euid = geteuid();
+	*gid = getgid();
+
+	return (0);
+}
+#endif /* defined(SO_PEERCRED) */
+
+#endif /* !defined(HAVE_GETPEEREID) */

Added: trunk/replace/setenv.c
===================================================================
--- trunk/replace/setenv.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/replace/setenv.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV)
+
+static char *__findenv(const char *name, int *offset);
+#ifndef HAVE_SETENV
+int setenv(const char *, const char *, int);
+#endif
+#ifndef HAVE_UNSETENV
+void unsetenv(const char *);
+#endif
+extern char **environ;
+
+/*
+ * __findenv --
+ *	Returns pointer to value associated with name, if any, else NULL.
+ *	Sets offset to be the offset of the name/value combination in the
+ *	environmental array, for use by setenv(3) and unsetenv(3).
+ *	Explicitly removes '=' in argument name.
+ *
+ *	This routine *should* be a static; don't use it.
+ */
+static char *
+__findenv(name, offset)
+	register const char *name;
+	int *offset;
+{
+	register int len, i;
+	register const char *np;
+	register char **p, *cp;
+
+	if (name == NULL || environ == NULL)
+		return (NULL);
+	for (np = name; *np && *np != '='; ++np)
+		;
+	len = np - name;
+	for (p = environ; (cp = *p) != NULL; ++p) {
+		for (np = name, i = len; i && *cp; i--)
+			if (*cp++ != *np++)
+				break;
+		if (i == 0 && *cp++ == '=') {
+			*offset = p - environ;
+			return (cp);
+		}
+	}
+	return (NULL);
+}
+
+#ifndef HAVE_SETENV
+/*
+ * setenv --
+ *	Set the value of the environmental variable "name" to be
+ *	"value".  If rewrite is set, replace any current value.
+ */
+int
+setenv(name, value, rewrite)
+	register const char *name;
+	register const char *value;
+	int rewrite;
+{
+	static int alloced;			/* if allocated space before */
+	register char *C;
+	int offset;
+	size_t l_value;
+
+	if (*value == '=')			/* no `=' in value */
+		++value;
+	l_value = strlen(value);
+	if ((C = __findenv(name, &offset))) {	/* find if already exists */
+		if (!rewrite)
+			return (0);
+		if (strlen(C) >= l_value) {	/* old larger; copy over */
+			while ((*C++ = *value++))
+				;
+			return (0);
+		}
+	} else {					/* create new slot */
+		register int	cnt;
+		register char	**P;
+
+		for (P = environ, cnt = 0; *P; ++P, ++cnt);
+		if (alloced) {			/* just increase size */
+			P = (char **)realloc((void *)environ,
+			    (size_t)(sizeof(char *) * (cnt + 2)));
+			if (!P)
+				return (-1);
+			environ = P;
+		}
+		else {				/* get new space */
+			alloced = 1;		/* copy old entries into it */
+			P = (char **)malloc((size_t)(sizeof(char *) *
+			    (cnt + 2)));
+			if (!P)
+				return (-1);
+			memmove(P, environ, cnt * sizeof(char *));
+			environ = P;
+		}
+		environ[cnt + 1] = NULL;
+		offset = cnt;
+	}
+	for (C = (char *)name; *C && *C != '='; ++C);	/* no `=' in name */
+	if (!(environ[offset] =			/* name + `=' + value */
+	    malloc((size_t)((int)(C - name) + l_value + 2))))
+		return (-1);
+	for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
+		;
+	for (*C++ = '='; (*C++ = *value++); )
+		;
+	return (0);
+}
+#endif /* HAVE_SETENV */
+
+#ifndef HAVE_UNSETENV
+/*
+ * unsetenv(name) --
+ *	Delete environmental variable "name".
+ */
+void
+unsetenv(name)
+	const char	*name;
+{
+	register char **P;
+	int offset;
+
+	while (__findenv(name, &offset))		/* if set multiple times */
+		for (P = &environ[offset];; ++P)
+			if (!(*P = *(P + 1)))
+				break;
+}
+#endif /* HAVE_UNSETENV */
+
+#endif /* !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) */
+
+#if 0
+/*
+ * I doubt uim_setenv and uim_unsetenv are really needed. Only libuim and
+ * uim-module-manager uses setenv and unsetenv. I choose linking libreplace.la
+ * to both of them for OSes not having setenv and unsetenv. If setenv and
+ * unsetenv are used in out of the uim, please uncomment.
+ *
+ * In any cases, we have to upgrade minor version of libuim.
+ * -- omote 09/17/2005
+ */
+
+int
+uim_setenv(const char *name, const char *value, const char *rewrite)
+{
+  setenv(name, value, rewrite);
+}
+
+void
+uim_unsetenv(const char *name)
+{
+  unsetenv(name);
+}
+#endif

Added: trunk/replace/strsep.c
===================================================================
--- trunk/replace/strsep.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/replace/strsep.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include <string.h>
+#include <stdio.h>
+
+#if !defined(HAVE_STRSEP)
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.  
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep(char **stringp, const char *delim)
+{
+	char *s;
+	const char *spanp;
+	int c, sc;
+	char *tok;
+
+	if ((s = *stringp) == NULL)
+		return (NULL);
+	for (tok = s;;) {
+		c = *s++;
+		spanp = delim;
+		do {
+			if ((sc = *spanp++) == c) {
+				if (c == 0)
+					s = NULL;
+				else
+					s[-1] = 0;
+				*stringp = s;
+				return (tok);
+			}
+		} while (sc != 0);
+	}
+	/* NOTREACHED */
+}
+
+#endif /* !defined(HAVE_STRSEP) */
+
+/*
+ * uim_strsep is needed for keeping libuim's ABI.
+ */
+char *
+uim_strsep(char **stringp, const char *delim)
+{
+  strsep(stringp, delim);
+}

Modified: trunk/uim/Makefile.am
===================================================================
--- trunk/uim/Makefile.am	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/uim/Makefile.am	2005-09-16 18:04:07 UTC (rev 1506)
@@ -17,15 +17,15 @@
 		uim-helper.c uim-helper-client.c \
 		intl.c \
 		uim-ipc.c \
-		getpeereid.c \
 		plugin.c
+#		getpeereid.c
 
-if NEED_SETENV_C
-libuim_la_SOURCES += setenv.c
-endif
-if NEED_STRSEP_C
-libuim_la_SOURCES += strsep.c
-endif
+#if NEED_SETENV_C
+#libuim_la_SOURCES += setenv.c
+#endif
+#if NEED_STRSEP_C
+#libuim_la_SOURCES += strsep.c
+#endif
 
 if COMPAT_TABLE
 libuim_la_SOURCES += uim-table.c
@@ -85,8 +85,8 @@
 
 libuimincludedir =  $(includedir)/uim
 
-libuim_la_LDFLAGS = -version-info 0:1:0 -export-symbols-regex uim.\*
-libuim_la_LIBADD = @LTLIBINTL@ @LTLIBICONV@
+libuim_la_LDFLAGS = -version-info 0:2:0 -export-symbols-regex uim.\*
+libuim_la_LIBADD = @LTLIBINTL@ @LTLIBICONV@ $(top_srcdir)/replace/libreplace.la
 libuim_la_CPPFLAGS = $(uim_defs) -I$(top_srcdir) -DPKGLIBDIR=\"$(pkglibdir)\" \
 		     -DPKGDATADIR=\"$(pkgdatadir)\"
 
@@ -127,11 +127,11 @@
 uim_module_manager_LIBS =
 uim_module_manager_CPPFLAGS = $(uim_defs) -I$(top_srcdir) -DUIM_DATADIR=\""$(datadir)/uim"\"
 uim_module_manager_CFLAGS =
-uim_module_manager_LDADD = libuim.la
+uim_module_manager_LDADD = libuim.la $(top_srcdir)/replace/libreplace.la
 uim_module_manager_SOURCES = uim-module-manager.c
-if NEED_SETENV_C
-uim_module_manager_SOURCES += setenv.c
-endif
+#if NEED_SETENV_C
+#uim_module_manager_SOURCES += setenv.c
+#endif
 
 noinst_PROGRAMS = uim-agent
 

Deleted: trunk/uim/getpeereid.c
===================================================================
--- trunk/uim/getpeereid.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/uim/getpeereid.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2002,2004 Damien Miller <djm at mindrot.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, 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.
- */
-
-#include "config.h"
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/param.h>
-#include "uim.h"
-#include "uim-helper.h"
-
-#if !defined(HAVE_GETPEEREID)
-
-#if defined(SO_PEERCRED)
-static int
-getpeereid(int s, uid_t *euid, gid_t *gid)
-{
-	struct ucred cred;
-	socklen_t len = sizeof(cred);
-
-	if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
-		return (-1);
-	*euid = cred.uid;
-	*gid = cred.gid;
-
-	return (0);
-}
-#elif defined(LOCAL_CREDS)	/* NetBSD */
-int
-getpeereid(int s, uid_t *euid, gid_t *gid)
-{
-/* Credentials structure */
-#ifdef __NetBSD__	/* XXX: should use autoconf */
-#define HAVE_STRUCT_SOCKCRED
-#endif
-#if defined(HAVE_STRUCT_CMSGCRED)
-        typedef struct cmsgcred Cred;
-
-#define cruid cmcred_euid
-#define crgid cmcred_groups[0]
-#elif defined(HAVE_STRUCT_FCRED)
-        typedef struct fcred Cred;
-
-#define cruid fc_uid
-#define crgid fc_gid
-#elif defined(HAVE_STRUCT_SOCKCRED)
-        typedef struct sockcred Cred;
-
-#define cruid sc_euid
-#define crgid sc_egid
-#endif
-        Cred *cred;
-
-        /* Compute size without padding */
-        char cmsgmem[CMSG_SPACE(sizeof(Cred))]; /* for NetBSD */
-
-        /* Point to start of first structure */
-        struct cmsghdr *cmsg = (struct cmsghdr *)cmsgmem;
-
-        struct iovec iov;
-        char buf;
-        struct msghdr msg;
-
-        memset(&msg, 0, sizeof(msg));
-        msg.msg_iov = &iov;
-        msg.msg_iovlen = 1;
-        msg.msg_control = (char *)cmsg;
-        msg.msg_controllen = sizeof(cmsgmem);
-        memset(cmsg, 0, sizeof(cmsgmem));
-
-        /*
-         * The one character which is received here is not meaningful; its
-         * purposes is only to make sure that recvmsg() blocks long enough for
-         * the other side to send its credentials.
-         */
-        iov.iov_base = &buf;
-        iov.iov_len = 1;
-
-        if (recvmsg(s, &msg, 0) < 0 ||
-                cmsg->cmsg_len < sizeof(cmsgmem) ||
-                cmsg->cmsg_type != SCM_CREDS)
-        {
-                return -1;
-        }
-
-        cred = (Cred *)CMSG_DATA(cmsg);
-	*euid = cred->cruid;
-	*gid = cred->crgid;
-
-	return 0;
-}
-#else
-static int
-getpeereid(int s, uid_t *euid, gid_t *gid)
-{
-	*euid = geteuid();
-	*gid = getgid();
-
-	return (0);
-}
-#endif /* defined(SO_PEERCRED) */
-
-#endif /* !defined(HAVE_GETPEEREID) */
-int
-uim_helper_check_connection_fd(int fd)
-{
-  uid_t euid;
-  gid_t egid;
-  if (getpeereid(fd, &euid, &egid) < 0) {
-    perror("getpeereid failed");
-    return -1;
-  }
-  if ((euid != 0) && (euid != getuid())) {
-    fprintf(stderr, "uid mismatch\n");
-    return -1;
-  }
-  return 0;
-}

Deleted: trunk/uim/setenv.c
===================================================================
--- trunk/uim/setenv.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/uim/setenv.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "config.h"
-#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV)
-
-static char *__findenv(const char *name, int *offset);
-#ifndef HAVE_SETENV
-int setenv(const char *, const char *, int);
-#endif
-#ifndef HAVE_UNSETENV
-void unsetenv(const char *);
-#endif
-extern char **environ;
-
-/*
- * __findenv --
- *	Returns pointer to value associated with name, if any, else NULL.
- *	Sets offset to be the offset of the name/value combination in the
- *	environmental array, for use by setenv(3) and unsetenv(3).
- *	Explicitly removes '=' in argument name.
- *
- *	This routine *should* be a static; don't use it.
- */
-static char *
-__findenv(name, offset)
-	register const char *name;
-	int *offset;
-{
-	register int len, i;
-	register const char *np;
-	register char **p, *cp;
-
-	if (name == NULL || environ == NULL)
-		return (NULL);
-	for (np = name; *np && *np != '='; ++np)
-		;
-	len = np - name;
-	for (p = environ; (cp = *p) != NULL; ++p) {
-		for (np = name, i = len; i && *cp; i--)
-			if (*cp++ != *np++)
-				break;
-		if (i == 0 && *cp++ == '=') {
-			*offset = p - environ;
-			return (cp);
-		}
-	}
-	return (NULL);
-}
-
-#ifndef HAVE_SETENV
-/*
- * setenv --
- *	Set the value of the environmental variable "name" to be
- *	"value".  If rewrite is set, replace any current value.
- */
-int
-setenv(name, value, rewrite)
-	register const char *name;
-	register const char *value;
-	int rewrite;
-{
-	static int alloced;			/* if allocated space before */
-	register char *C;
-	int offset;
-	size_t l_value;
-
-	if (*value == '=')			/* no `=' in value */
-		++value;
-	l_value = strlen(value);
-	if ((C = __findenv(name, &offset))) {	/* find if already exists */
-		if (!rewrite)
-			return (0);
-		if (strlen(C) >= l_value) {	/* old larger; copy over */
-			while ((*C++ = *value++))
-				;
-			return (0);
-		}
-	} else {					/* create new slot */
-		register int	cnt;
-		register char	**P;
-
-		for (P = environ, cnt = 0; *P; ++P, ++cnt);
-		if (alloced) {			/* just increase size */
-			P = (char **)realloc((void *)environ,
-			    (size_t)(sizeof(char *) * (cnt + 2)));
-			if (!P)
-				return (-1);
-			environ = P;
-		}
-		else {				/* get new space */
-			alloced = 1;		/* copy old entries into it */
-			P = (char **)malloc((size_t)(sizeof(char *) *
-			    (cnt + 2)));
-			if (!P)
-				return (-1);
-			memmove(P, environ, cnt * sizeof(char *));
-			environ = P;
-		}
-		environ[cnt + 1] = NULL;
-		offset = cnt;
-	}
-	for (C = (char *)name; *C && *C != '='; ++C);	/* no `=' in name */
-	if (!(environ[offset] =			/* name + `=' + value */
-	    malloc((size_t)((int)(C - name) + l_value + 2))))
-		return (-1);
-	for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
-		;
-	for (*C++ = '='; (*C++ = *value++); )
-		;
-	return (0);
-}
-#endif /* HAVE_SETENV */
-
-#ifndef HAVE_UNSETENV
-/*
- * unsetenv(name) --
- *	Delete environmental variable "name".
- */
-void
-unsetenv(name)
-	const char	*name;
-{
-	register char **P;
-	int offset;
-
-	while (__findenv(name, &offset))		/* if set multiple times */
-		for (P = &environ[offset];; ++P)
-			if (!(*P = *(P + 1)))
-				break;
-}
-#endif /* HAVE_UNSETENV */
-
-#endif /* !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) */

Deleted: trunk/uim/strsep.c
===================================================================
--- trunk/uim/strsep.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/uim/strsep.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -1,74 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-#include <string.h>
-#include <stdio.h>
-
-#if !defined(HAVE_STRSEP)
-
-/*
- * Get next token from string *stringp, where tokens are possibly-empty
- * strings separated by characters from delim.  
- *
- * Writes NULs into the string at *stringp to end tokens.
- * delim need not remain constant from call to call.
- * On return, *stringp points past the last NUL written (if there might
- * be further tokens), or is NULL (if there are definitely no more tokens).
- *
- * If *stringp is NULL, strsep returns NULL.
- */
-char *
-uim_strsep(char **stringp, const char *delim)
-{
-	char *s;
-	const char *spanp;
-	int c, sc;
-	char *tok;
-
-	if ((s = *stringp) == NULL)
-		return (NULL);
-	for (tok = s;;) {
-		c = *s++;
-		spanp = delim;
-		do {
-			if ((sc = *spanp++) == c) {
-				if (c == 0)
-					s = NULL;
-				else
-					s[-1] = 0;
-				*stringp = s;
-				return (tok);
-			}
-		} while (sc != 0);
-	}
-	/* NOTREACHED */
-}
-
-#endif /* !defined(HAVE_STRSEP) */

Modified: trunk/uim/uim-ipc.c
===================================================================
--- trunk/uim/uim-ipc.c	2005-09-16 16:31:57 UTC (rev 1505)
+++ trunk/uim/uim-ipc.c	2005-09-16 18:04:07 UTC (rev 1506)
@@ -47,11 +47,6 @@
 #include "uim-helper.h"
 #include "uim-util.h"
 
-#ifndef HAVE_STRSEP
-char *uim_strsep(char **stringp, const char *delim);
-#define strsep	uim_strsep
-#endif
-
 /* This function is come from the GNU C Library manual */
 static int
 set_cloexec(int fd)
@@ -296,3 +291,19 @@
   *pid = uim_ipc_open_command(*pid, read_fp, write_fp, command);
   return NULL;
 }
+
+int
+uim_helper_check_connection_fd(int fd)
+{
+  uid_t euid;
+  gid_t egid;
+  if (getpeereid(fd, &euid, &egid) < 0) {
+    perror("getpeereid failed");
+    return -1;
+  }
+  if ((euid != 0) && (euid != getuid())) {
+    fprintf(stderr, "uid mismatch\n");
+    return -1;
+  }
+  return 0;
+}



More information about the uim-commit mailing list