usr/src/cmd/rad/mod/xport_unix/mod_xport_unix.c
changeset 798 a7deccd6492f
parent 717 7f7fc966a88f
child 817 a1315f6ad037
--- a/usr/src/cmd/rad/mod/xport_unix/mod_xport_unix.c	Wed Feb 01 09:22:41 2012 -0500
+++ b/usr/src/cmd/rad/mod/xport_unix/mod_xport_unix.c	Thu Feb 02 11:25:01 2012 -0500
@@ -20,11 +20,12 @@
  */
 
 /*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
  */
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <bsm/adt_event.h>
 #include <stdio.h>
 #include <string.h>
@@ -64,11 +65,48 @@
 }
 
 static int
+create_tmpdir(const char *name)
+{
+	int retval = 0;
+	struct stat st;
+	mode_t um;
+
+	int i = strncmp(name, RAD_TMPDIR "/", strlen(RAD_TMPDIR "/"));
+
+	if (i == 0) {	/* Default path specified */
+		if (stat(RAD_TMPDIR, &st) == 0) {
+			if (!S_ISDIR(st.st_mode)) {
+				rad_log(RL_ERROR, "file '%s' exists.",
+				    RAD_TMPDIR);
+				retval = -1;
+			}
+		} else if (errno == ENOENT) { /* Create it */
+			um = umask(0);
+			i = mkdir(RAD_TMPDIR, S_IRWXU | S_IRWXG | S_IRWXO);
+			umask(um);
+			if (i != 0) {
+				rad_log(RL_ERROR, "error creating '%s': %s."
+				    RAD_TMPDIR, strerror(errno));
+				retval = -1;
+			}
+		} else {
+			rad_log(RL_ERROR, "error creating '%s': %s."
+			    RAD_TMPDIR, strerror(errno));
+			retval = -1;
+		}
+	}
+	return (retval);
+}
+
+static int
 listen_on_name(const char *name)
 {
 	int fd;
 	struct sockaddr_un addr;
 
+	if (create_tmpdir(name) != 0)
+		return (-1);
+
 	if (unlink(name) == -1 && errno != ENOENT) {
 		rad_log(RL_ERROR, "unlink of '%s' failed: %s", name,
 		    strerror(errno));