/*
* 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 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* User-space door client for LanMan share management.
*/
#include <syslog.h>
#include <door.h>
#include <fcntl.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <thread.h>
#include <synch.h>
#include <smbsrv/smb_share.h>
static int smb_share_door_clnt_open(void);
static void smb_share_door_clnt_close(void);
void
smb_share_door_clnt_init(void)
{
(void) mutex_lock(&smb_share_dmtx);
(void) smb_share_door_clnt_open();
(void) mutex_unlock(&smb_share_dmtx);
}
void
smb_share_door_clnt_fini(void)
{
(void) mutex_lock(&smb_share_dmtx);
(void) mutex_unlock(&smb_share_dmtx);
}
/*
* Open smb_share_door. This is a private call for use by
* smb_share_door_clnt_enter() and must be called with smb_share_dmtx held.
*
* Returns the door fd on success. Otherwise, -1.
*/
static int
smb_share_door_clnt_open(void)
{
const char *door_name;
if (smb_share_dfd == -1) {
smb_share_dfd = -1;
else
smb_share_dncall = 0;
}
return (smb_share_dfd);
}
/*
* Close smb_share_door.
* Private call that must be called with smb_share_dmtx held.
*/
static void
{
if (smb_share_dfd != -1) {
while (smb_share_dncall > 0)
if (smb_share_dfd != -1) {
(void) close(smb_share_dfd);
smb_share_dfd = -1;
}
}
}
/*
* Entry handler for smb_share_door calls.
*/
static door_arg_t *
{
char *buf;
(void) mutex_lock(&smb_share_dmtx);
if (smb_share_door_clnt_open() == -1) {
(void) mutex_unlock(&smb_share_dmtx);
return (NULL);
}
}
(void) mutex_unlock(&smb_share_dmtx);
return (arg);
}
/*
* Exit handler for smb_share_door calls.
*/
static void
{
if (errmsg)
(void) mutex_lock(&smb_share_dmtx);
(void) cond_signal(&smb_share_dcv);
if (must_close)
(void) mutex_unlock(&smb_share_dmtx);
}
static int
{
int rc;
int i;
for (i = 0; i < SMB_SHARE_DOOR_CALL_RETRIES; ++i) {
errno = 0;
break;
break;
}
return (rc);
}
static int
{
if (status != SMB_SHARE_DSUCCESS) {
if (status == SMB_SHARE_DERROR)
(void) smb_dr_get_uint32(dec_ctx);
return (-1);
}
return (0);
}
{
return (NERR_InternalError);
if (rc != 0) {
return (NERR_InternalError);
}
return (NERR_InternalError);
}
if (smb_share_dchk(dec_ctx) != 0) {
(void) smb_dr_decode_finish(dec_ctx);
return (NERR_InternalError);
}
sizeof (smb_shrlist_t));
if (smb_dr_decode_finish(dec_ctx) != 0) {
return (NERR_InternalError);
}
return (NERR_Success);
}
int
smb_share_count(void)
{
int rc;
return (-1);
if (rc != 0) {
return (-1);
}
return (-1);
}
if (smb_share_dchk(dec_ctx) != 0) {
(void) smb_dr_decode_finish(dec_ctx);
return (-1);
}
if (smb_dr_decode_finish(dec_ctx) != 0) {
return (-1);
}
return (num_shares);
}
{
return (NERR_InternalError);
if (rc != 0) {
return (NERR_InternalError);
}
return (NERR_InternalError);
}
if (smb_share_dchk(dec_ctx) != 0) {
(void) smb_dr_decode_finish(dec_ctx);
return (NERR_InternalError);
}
if (smb_dr_decode_finish(dec_ctx) != 0) {
return (NERR_InternalError);
}
return (rc);
}
{
return (NERR_InternalError);
if (rc != 0) {
return (NERR_InternalError);
}
return (NERR_InternalError);
}
if (smb_share_dchk(dec_ctx) != 0) {
(void) smb_dr_decode_finish(dec_ctx);
return (NERR_InternalError);
}
if (smb_dr_decode_finish(dec_ctx) != 0) {
return (NERR_InternalError);
}
return (rc);
}
{
return (NERR_InternalError);
if (rc != 0) {
return (NERR_InternalError);
}
return (NERR_InternalError);
}
if (smb_share_dchk(dec_ctx) != 0) {
(void) smb_dr_decode_finish(dec_ctx);
return (NERR_InternalError);
}
if (smb_dr_decode_finish(dec_ctx) != 0) {
return (NERR_InternalError);
}
return (rc);
}
{
return (NERR_InternalError);
if (rc != 0) {
return (NERR_InternalError);
}
return (NERR_InternalError);
}
if (smb_share_dchk(dec_ctx) != 0) {
(void) smb_dr_decode_finish(dec_ctx);
return (NERR_InternalError);
}
if (smb_dr_decode_finish(dec_ctx) != 0) {
return (NERR_InternalError);
}
return (rc);
}