smbd_doorsvc.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* SMBd door server
*/
#include <alloca.h>
#include <door.h>
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
#include <varargs.h>
#include <stdio.h>
#include <synch.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <pthread.h>
#include <strings.h>
#include <smbsrv/smb_door_svc.h>
#include <smbsrv/smb_common_door.h>
static int smb_doorsrv_fildes = -1;
static mutex_t smb_doorsrv_mutex;
/*
* smb_door_srv_start
*
* Start the smbd door service. Create and bind to a door.
* Returns 0 on success. Otherwise, -1.
*/
int
{
int newfd;
(void) mutex_lock(&smb_doorsrv_mutex);
if (smb_doorsrv_fildes != -1) {
(void) mutex_unlock(&smb_doorsrv_mutex);
return (-1);
}
SMB_DR_SVC_COOKIE, DOOR_UNREF)) < 0) {
smb_doorsrv_fildes = -1;
(void) mutex_unlock(&smb_doorsrv_mutex);
return (-1);
}
(void) unlink(SMB_DR_SVC_NAME);
(void) door_revoke(smb_doorsrv_fildes);
smb_doorsrv_fildes = -1;
(void) mutex_unlock(&smb_doorsrv_mutex);
return (-1);
}
(void) fdetach(SMB_DR_SVC_NAME);
(void) door_revoke(smb_doorsrv_fildes);
smb_doorsrv_fildes = -1;
(void) mutex_unlock(&smb_doorsrv_mutex);
return (-1);
}
(void) mutex_unlock(&smb_doorsrv_mutex);
return (0);
}
/*
* smb_door_srv_stop
*
* Stop the smbd door service.
*/
void
smb_door_srv_stop(void)
{
(void) mutex_lock(&smb_doorsrv_mutex);
if (smb_doorsrv_fildes != -1) {
(void) fdetach(SMB_DR_SVC_NAME);
(void) door_revoke(smb_doorsrv_fildes);
smb_doorsrv_fildes = -1;
}
(void) mutex_unlock(&smb_doorsrv_mutex);
}
/*
* smb_door_err_hdlr
*
* Encode the appropriate error code to the first 4-byte of the result
* buffer upon any door operation failure.
*/
static char *
{
char *rbuf;
*rbufsize = 0;
return (NULL);
}
return (rbuf);
}
/*
* smb_door_srv_func
*
* This function will determine the opcode by decoding the first 4-byte of
* the argument buffer passed by a door client. The corresponding door
* operation will be looked up from the optab and get invoked.
* Basically, any door operation will takes the argument buffer as its
* parameter, and generates the result buffer.
*/
/*ARGSUSED*/
void
{
int opcode;
int err;
&rbufsize);
goto door_return;
}
"(opcode=%d)", opcode);
if (smb_dr_is_valid_opcode(opcode) != 0) {
&rbufsize);
} else {
}
if (tmpbuf) {
rbufsize = 0;
else
}
/*NOTREACHED*/
}