[asterisk-commits] eliel: branch eliel/cli-permissions r159770 - in /team/eliel/cli-permissions:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 28 11:35:09 CST 2008


Author: eliel
Date: Fri Nov 28 11:35:09 2008
New Revision: 159770

URL: http://svn.digium.com/view/asterisk?view=rev&rev=159770
Log:
Fix a compatibility issue in OpenBSD with SCM_CREDENTIALS, also simplify read_credentials.

Modified:
    team/eliel/cli-permissions/configure
    team/eliel/cli-permissions/configure.ac
    team/eliel/cli-permissions/include/asterisk/autoconfig.h.in
    team/eliel/cli-permissions/main/asterisk.c

Modified: team/eliel/cli-permissions/configure.ac
URL: http://svn.digium.com/view/asterisk/team/eliel/cli-permissions/configure.ac?view=diff&rev=159770&r1=159769&r2=159770
==============================================================================
--- team/eliel/cli-permissions/configure.ac (original)
+++ team/eliel/cli-permissions/configure.ac Fri Nov 28 11:35:09 2008
@@ -336,7 +336,7 @@
 AC_FUNC_STRTOD
 AC_FUNC_UTIME_NULL
 AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf])
+AC_CHECK_FUNCS([asprintf atexit dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf getpeereid])
 
 AC_CHECK_FUNCS([glob])
 

Modified: team/eliel/cli-permissions/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/view/asterisk/team/eliel/cli-permissions/include/asterisk/autoconfig.h.in?view=diff&rev=159770&r1=159769&r2=159770
==============================================================================
--- team/eliel/cli-permissions/include/asterisk/autoconfig.h.in (original)
+++ team/eliel/cli-permissions/include/asterisk/autoconfig.h.in Fri Nov 28 11:35:09 2008
@@ -321,6 +321,9 @@
 
 /* Define to 1 if you have the `getpagesize' function. */
 #undef HAVE_GETPAGESIZE
+
+/* Define to 1 if you have the `getpeereid' function. */
+#undef HAVE_GETPEEREID
 
 /* Define to 1 if you have the `gettimeofday' function. */
 #undef HAVE_GETTIMEOFDAY
@@ -1218,6 +1221,9 @@
 #ifndef _POSIX_PTHREAD_SEMANTICS
 # undef _POSIX_PTHREAD_SEMANTICS
 #endif
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
 
 /* Define like PROTOTYPES; this can be used by system headers. */
 #undef __PROTOTYPES

Modified: team/eliel/cli-permissions/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/eliel/cli-permissions/main/asterisk.c?view=diff&rev=159770&r1=159769&r2=159770
==============================================================================
--- team/eliel/cli-permissions/main/asterisk.c (original)
+++ team/eliel/cli-permissions/main/asterisk.c Fri Nov 28 11:35:09 2008
@@ -1003,41 +1003,30 @@
 static int read_credentials(int fd, char *buffer, size_t size, struct console *con)
 {
 	struct ucred cred;
-	struct cmsghdr *cmsg;
-	struct iovec iov;
-	int result;
-	struct msghdr msg = {
-		.msg_iov = &iov,
-		.msg_iovlen = 1,
-		.msg_control = NULL,
-		.msg_controllen = 0,
-		.msg_flags = 0
-	};
-
-	memset(&cred, 0, sizeof(cred));
-
-	iov.iov_len = size;
-	iov.iov_base = buffer;
-
-	msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
-	msg.msg_control = ast_calloc(1, msg.msg_controllen);
-
-	result = recvmsg(fd, &msg, 0);
+	socklen_t len = sizeof(cred);
+	int result, uid, gid;
+
+	result = read(fd, buffer, size);
 	if (result < 0) {
-		ast_log (LOG_ERROR, "Error receiving credentials msg\n");
-		ast_free(msg.msg_control);
-		return -1;
-	}
-
-	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
-		if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type  == SCM_CREDENTIALS) {
-			memcpy(&cred, CMSG_DATA(cmsg), sizeof(cred));
-			break;
-		}
-	}
-	con->uid = cred.uid;
-	con->gid = cred.gid;
-	ast_free(msg.msg_control);
+		return result;
+	}
+
+#if defined(SO_PEERCRED)
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len)) {
+		return result;
+	}
+	uid = cred.uid;
+	gid = cred.gid;
+#elif defined(HAVE_GETPEEREID)
+	if (getpeereid(fd, &uid, &gid)) {
+		return result;
+	}
+#else
+	return result;
+#endif
+	con->uid = uid;
+	con->gid = gid;
+
 	return result;
 }
 
@@ -1107,7 +1096,6 @@
 	int x;
 	int flags;
 	struct pollfd fds[1];
-	int sckopt = 1;
 	for (;;) {
 		if (ast_socket < 0)
 			return NULL;
@@ -1126,10 +1114,15 @@
 			if (errno != EINTR)
 				ast_log(LOG_WARNING, "Accept returned %d: %s\n", s, strerror(errno));
 		} else {
+#if !defined(SO_PASSCRED)
+			{
+#else
+			int sckopt = 1;
 			/* turn on socket credentials passing. */
 			if (setsockopt(s, SOL_SOCKET, SO_PASSCRED, &sckopt, sizeof(sckopt)) < 0) {
 				ast_log(LOG_WARNING, "Unable to turn on socket credentials passing\n");
 			} else {
+#endif
 				for (x = 0; x < AST_MAX_CONNECTS; x++) {
 					if (consoles[x].fd >= 0) {
 						continue;




More information about the asterisk-commits mailing list