usr/src/cmd/rad/mod/xport_unix/mod_unix.c
author Stephen Talley <stephen.talley@oracle.com>
Fri, 18 May 2012 11:08:12 -0400
changeset 862 f20f2afa6263
parent 852 usr/src/cmd/rad/mod/xport_unix/mod_xport_unix.c@bcfb754700ce
permissions -rw-r--r--
mod_xport -> mod
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     1
/*
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     2
 * CDDL HEADER START
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     3
 *
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     7
 *
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    12
 *
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    18
 *
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    20
 */
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    21
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    22
/*
798
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    23
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    24
 */
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    25
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    26
#include <sys/types.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    27
#include <sys/socket.h>
798
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    28
#include <sys/stat.h>
612
670030d74969 17519 PAM conversation needs to handle password expiry
David Powell <david.e.powell@oracle.com>
parents: 543
diff changeset
    29
#include <bsm/adt_event.h>
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    30
#include <stdio.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    31
#include <string.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    32
#include <stdlib.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    33
#include <errno.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    34
#include <unistd.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    35
#include <pthread.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    36
#include <ucred.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    37
#include <zone.h>
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    38
543
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
    39
#include <rad/adr_stream.h>
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    40
#include "rad_object.h"
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    41
#include "rad_modapi.h"
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    42
#include "rad_modapi_xport.h"
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    43
#include "rad_connection.h"
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    44
#include "rad_xport.h"
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    45
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
    46
#include "api_unix.h"
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    47
834
1e5c5d230679 7161020 - RAD build is broken in solaris11u1 build 13
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 817
diff changeset
    48
static char *pam_service = "rad-unix";
817
a1315f6ad037 7141333 RAD PAM service names should be public, committed, and documented
Stephen Talley <stephen.talley@oracle.com>
parents: 798
diff changeset
    49
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    50
static boolean_t
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    51
sockaddr_init(struct sockaddr_un *addr, const char *name)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    52
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    53
	size_t namelen;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    54
	size_t addrlen;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    55
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    56
	(void) memset(addr, 0, sizeof (*addr));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    57
	addr->sun_family = AF_UNIX;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    58
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    59
	namelen = strlen(name);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    60
	addrlen = sizeof (addr->sun_path);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    61
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    62
	if (namelen >= addrlen)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    63
		return (B_FALSE);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    64
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    65
	(void) strlcpy(addr->sun_path, name, sizeof (addr->sun_path));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    66
	return (B_TRUE);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    67
}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    68
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
    69
static int
798
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    70
create_tmpdir(const char *name)
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    71
{
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    72
	int retval = 0;
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    73
	struct stat st;
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    74
	mode_t um;
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    75
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    76
	int i = strncmp(name, RAD_TMPDIR "/", strlen(RAD_TMPDIR "/"));
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    77
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    78
	if (i == 0) {	/* Default path specified */
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    79
		if (stat(RAD_TMPDIR, &st) == 0) {
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    80
			if (!S_ISDIR(st.st_mode)) {
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    81
				rad_log(RL_ERROR, "file '%s' exists.",
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    82
				    RAD_TMPDIR);
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    83
				retval = -1;
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    84
			}
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    85
		} else if (errno == ENOENT) { /* Create it */
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    86
			um = umask(0);
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    87
			i = mkdir(RAD_TMPDIR, S_IRWXU | S_IRWXG | S_IRWXO);
834
1e5c5d230679 7161020 - RAD build is broken in solaris11u1 build 13
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 817
diff changeset
    88
			(void) umask(um);
798
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    89
			if (i != 0) {
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    90
				rad_log(RL_ERROR, "error creating '%s': %s."
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    91
				    RAD_TMPDIR, strerror(errno));
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    92
				retval = -1;
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    93
			}
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    94
		} else {
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    95
			rad_log(RL_ERROR, "error creating '%s': %s."
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    96
			    RAD_TMPDIR, strerror(errno));
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    97
			retval = -1;
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    98
		}
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
    99
	}
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   100
	return (retval);
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   101
}
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   102
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   103
static int
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   104
listen_on_name(const char *name)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   105
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   106
	int fd;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   107
	struct sockaddr_un addr;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   108
798
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   109
	if (create_tmpdir(name) != 0)
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   110
		return (-1);
a7deccd6492f CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
devjani.ray@oracle.com <devjani.ray@oracle.com>
parents: 717
diff changeset
   111
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   112
	if (unlink(name) == -1 && errno != ENOENT) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   113
		rad_log(RL_ERROR, "unlink of '%s' failed: %s", name,
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   114
		    strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   115
		return (-1);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   116
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   117
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   118
	if (!sockaddr_init(&addr, name)) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   119
		rad_log(RL_ERROR, "socket name '%s' too long", name);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   120
		return (-1);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   121
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   122
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   123
	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   124
		rad_log(RL_ERROR, "socket failed: %s", strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   125
		return (-1);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   126
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   127
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   128
	if (bind(fd, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   129
		rad_log(RL_ERROR, "bind to '%s' failed: %s", name,
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   130
		    strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   131
		(void) close(fd);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   132
		return (-1);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   133
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   134
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   135
	if (listen(fd, 15) == -1) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   136
		rad_log(RL_ERROR, "listen on '%s' failed: %s", name,
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   137
		    strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   138
		return (-1);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   139
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   140
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   141
	return (fd);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   142
}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   143
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   144
/*
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   145
 * Determines if the ucred represents someone who is effectively us.
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   146
 */
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   147
static boolean_t
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   148
sent_by_joe(ucred_t *uc)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   149
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   150
	const priv_set_t *theirprivs;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   151
	priv_set_t *myprivs = priv_allocset();
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   152
	if (myprivs == NULL) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   153
		rad_log(RL_ERROR, "failed to allocate privilege set");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   154
		return (B_FALSE);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   155
	}
523
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   156
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   157
	/* Could handle this "gracefully", but it isn't supposed to fail */
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   158
	if (getppriv(PRIV_PERMITTED, myprivs) == -1)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   159
		rad_log(RL_FATAL, "getppriv(PRIV_PERMITTED) failed: %s",
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   160
		    strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   161
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   162
	if (uc == NULL ||
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   163
	    ucred_geteuid(uc) != getuid() ||
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   164
	    ucred_getzoneid(uc) != getzoneid() ||
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   165
	    (theirprivs = ucred_getprivset(uc, PRIV_EFFECTIVE)) == NULL ||
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   166
	    !priv_issubset(myprivs, theirprivs)) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   167
		priv_freeset(myprivs);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   168
		rad_log(RL_WARN, "unprivileged client (uid=%d) "
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   169
		    "attempted connection to control port", ucred_geteuid(uc));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   170
		return (B_FALSE);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   171
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   172
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   173
	priv_freeset(myprivs);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   174
	return (B_TRUE);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   175
}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   176
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   177
static void
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   178
unix_run(void *arg)
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   179
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   180
	radmod_connection_t *conn = arg;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   181
	rad_proto_handle(conn);
468
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   182
	rad_conn_free(conn);
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   183
}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   184
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   185
static rad_moderr_t
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   186
unix_listen(rad_thread_t *arg)
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   187
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   188
	data_t *data = rad_thread_arg(arg);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   189
	int fd;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   190
	data_t *d, *path = struct_get(data, "path");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   191
	d = struct_get(data, "proto");
500
d134d555588f 15908 create accessors for all ADR data
David Powell <david.e.powell@oracle.com>
parents: 468
diff changeset
   192
	const char *protostr = d != NULL ? data_to_string(d) : "rad";
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   193
	d = struct_get(data, "control");
500
d134d555588f 15908 create accessors for all ADR data
David Powell <david.e.powell@oracle.com>
parents: 468
diff changeset
   194
	boolean_t control = d != NULL ? data_to_boolean(d) : B_FALSE;
646
e1e91f5b0cb1 17807 implicit authorization over uds connection should be optional
Stephen Talley <stephen.talley@oracle.com>
parents: 612
diff changeset
   195
	d = struct_get(data, "peercred");
e1e91f5b0cb1 17807 implicit authorization over uds connection should be optional
Stephen Talley <stephen.talley@oracle.com>
parents: 612
diff changeset
   196
	boolean_t peercred = d != NULL ? data_to_boolean(d) : B_TRUE;
817
a1315f6ad037 7141333 RAD PAM service names should be public, committed, and documented
Stephen Talley <stephen.talley@oracle.com>
parents: 798
diff changeset
   197
	d = struct_get(data, "pam_service");
a1315f6ad037 7141333 RAD PAM service names should be public, committed, and documented
Stephen Talley <stephen.talley@oracle.com>
parents: 798
diff changeset
   198
	if (d != NULL) {
a1315f6ad037 7141333 RAD PAM service names should be public, committed, and documented
Stephen Talley <stephen.talley@oracle.com>
parents: 798
diff changeset
   199
		pam_service = (char *)data_to_string(d);
a1315f6ad037 7141333 RAD PAM service names should be public, committed, and documented
Stephen Talley <stephen.talley@oracle.com>
parents: 798
diff changeset
   200
	}
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   201
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   202
	rad_protocol_t *proto = rad_proto_find(protostr);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   203
	if (proto == NULL) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   204
		rad_log(RL_ERROR, "Unable to find protocol \"%s\".", protostr);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   205
		return (rm_config);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   206
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   207
500
d134d555588f 15908 create accessors for all ADR data
David Powell <david.e.powell@oracle.com>
parents: 468
diff changeset
   208
	if ((fd = listen_on_name(data_to_string(path))) < 0) {
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   209
		rad_log(RL_ERROR, "Error starting AF_UNIX server: %s",
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   210
		    strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   211
		return (rm_system);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   212
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   213
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   214
	rad_thread_ack(arg, rm_ok);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   215
	for (;;) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   216
		int afd;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   217
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   218
		rad_log(RL_DEBUG, "Waiting for connection.\n");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   219
		if ((afd = accept(fd, 0, 0)) == -1) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   220
			rad_log(RL_WARN, "Error in accept(): %s\n",
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   221
			    strerror(errno));
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   222
			continue;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   223
		}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   224
		rad_log(RL_DEBUG, "Connection accepted.\n");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   225
468
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   226
		/* subject allocation failure and missing ucred are conflated */
852
bcfb754700ce 7161108 - RAD should generate AUE_logout and AUE_role_logout audit events
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 834
diff changeset
   227
		rad_subject_t *subject = peercred ?
bcfb754700ce 7161108 - RAD should generate AUE_logout and AUE_role_logout audit events
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 834
diff changeset
   228
		    rad_subject_create_fd(afd, pam_service) : NULL;
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   229
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   230
		if (control) {
468
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   231
			if (subject == NULL) {
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   232
				(void) close(afd);
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   233
				continue;
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   234
			}
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   235
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   236
			if (!sent_by_joe(subject->rs_ucred)) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   237
				rad_subject_unref(subject);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   238
				(void) close(afd);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   239
				continue;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   240
			}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   241
			rad_log(RL_DEBUG,
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   242
			    "accepting connection on control port");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   243
			subject->rs_control = B_TRUE;
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   244
		}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   245
543
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   246
		adr_stream_t *stream = adr_stream_create_fd(afd);
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   247
		if (stream == NULL)
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   248
			continue;
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   249
468
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   250
		radmod_connection_t *conn = rad_conn_create_fd(afd, B_TRUE);
543
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   251
		if (conn == NULL) {
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   252
			adr_stream_close(stream);
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   253
			adr_stream_free(stream);
523
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   254
			rad_log(RL_WARN, "failed to allocate connection");
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   255
			continue;
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   256
		}
543
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   257
		conn->rm_conn_xport = stream;
aa62f8edcc3d 16605 need stream abstraction for handling non-fd based communication
David Powell <david.e.powell@oracle.com>
parents: 540
diff changeset
   258
		conn->rm_conn_proto_ops = proto;
817
a1315f6ad037 7141333 RAD PAM service names should be public, committed, and documented
Stephen Talley <stephen.talley@oracle.com>
parents: 798
diff changeset
   259
		conn->rm_conn_pam_service = pam_service;
523
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   260
612
670030d74969 17519 PAM conversation needs to handle password expiry
David Powell <david.e.powell@oracle.com>
parents: 543
diff changeset
   261
		if (subject != NULL &&
852
bcfb754700ce 7161108 - RAD should generate AUE_logout and AUE_role_logout audit events
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 834
diff changeset
   262
		    !rad_conn_setsubject(conn, subject)) {
523
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   263
			rad_conn_close(conn);
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   264
			rad_conn_free(conn);
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   265
			rad_log(RL_WARN, "failed to set connection subject");
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   266
			continue;
775c35bc3fe6 16318 make threading of Python client optional (cont)
David Powell <david.e.powell@oracle.com>
parents: 500
diff changeset
   267
		}
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   268
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   269
		if (rad_thread_create_async(unix_run, conn) != rm_ok) {
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   270
			rad_conn_close(conn);
468
7fa83d27b9f3 14970 python client misformats setattr requests
David Powell <David.Powell@sun.com>
parents: 426
diff changeset
   271
			rad_conn_free(conn);
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   272
		}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   273
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   274
}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   275
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   276
static rad_moderr_t
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   277
starter(data_t *data)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   278
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   279
	data_t *path = struct_get(data, "path");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   280
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   281
	if (path == NULL) {
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   282
		rad_log(RL_ERROR, "Unix domain socket requires path\n");
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   283
		return (rm_config);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   284
	}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   285
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   286
	return (rad_thread_create(unix_listen, data));
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   287
}
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   288
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   289
static rad_modinfo_t modinfo = {
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   290
	"xport_unix", "unix domain socket transport module",
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   291
};
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   292
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   293
int
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   294
_rad_init(void *handle)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   295
{
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   296
	if (rad_module_register(handle, RAD_MODVERSION, &modinfo) == -1)
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   297
		return (-1);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   298
710
beb915128edf 18431 Nobody says UDS
David Powell <david.e.powell@oracle.com>
parents: 646
diff changeset
   299
	rad_xport_register("unix", &t__unix, starter);
391
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   300
	return (0);
71abce159a62 13357 rad
David Powell <David.Powell@sun.com>
parents:
diff changeset
   301
}