smbd_share_doorsvc.c revision 3db3f65c6274eb042354801a308c8e9bc4994553
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* LanMan share door server
*/
#include <door.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <syslog.h>
#include <string.h>
#include <strings.h>
#include <pthread.h>
#include <smbsrv/smb_share.h>
#define SMB_SHARE_DSRV_VERSION 1
static int smb_share_dsrv_fd = -1;
uint_t);
/*
* smb_share_dsrv_start
*
* Start the LanMan share door service.
* Returns 0 on success. Otherwise, -1.
*/
int
smb_share_dsrv_start(void)
{
int newfd;
(void) pthread_mutex_lock(&smb_share_dsrv_mtx);
if (smb_share_dsrv_fd != -1) {
(void) pthread_mutex_unlock(&smb_share_dsrv_mtx);
return (smb_share_dsrv_fd);
}
(void) pthread_mutex_unlock(&smb_share_dsrv_mtx);
return (-1);
}
(void) unlink(SMB_SHARE_DNAME);
(void) door_revoke(smb_share_dsrv_fd);
smb_share_dsrv_fd = -1;
(void) pthread_mutex_unlock(&smb_share_dsrv_mtx);
return (-1);
}
(void) fdetach(SMB_SHARE_DNAME);
(void) door_revoke(smb_share_dsrv_fd);
smb_share_dsrv_fd = -1;
(void) pthread_mutex_unlock(&smb_share_dsrv_mtx);
return (-1);
}
(void) pthread_mutex_unlock(&smb_share_dsrv_mtx);
return (smb_share_dsrv_fd);
}
/*
* smb_share_dsrv_stop
*
* Stop the LanMan share door service.
*/
void
smb_share_dsrv_stop(void)
{
(void) pthread_mutex_lock(&smb_share_dsrv_mtx);
if (smb_share_dsrv_fd != -1) {
(void) fdetach(SMB_SHARE_DNAME);
(void) door_revoke(smb_share_dsrv_fd);
smb_share_dsrv_fd = -1;
}
(void) pthread_mutex_unlock(&smb_share_dsrv_mtx);
}
/*
* smb_share_dsrv_dispatch
*
* This function with which the LMSHARE door is associated
* will invoke the appropriate CIFS share management function
* based on the request type of the door call.
*/
/*ARGSUSED*/
static void
{
int req_type;
char buf[SMB_SHARE_DSIZE];
unsigned int used;
unsigned int dec_status;
unsigned int enc_status;
char *sharename, *sharename2;
int offset;
}
switch (req_type) {
case SMB_SHROP_NUM_SHARES:
goto decode_error;
rc = smb_shr_count();
break;
case SMB_SHROP_DELETE:
goto decode_error;
}
break;
case SMB_SHROP_RENAME:
goto decode_error;
}
break;
case SMB_SHROP_GETINFO:
goto decode_error;
}
break;
case SMB_SHROP_ADD:
goto decode_error;
break;
case SMB_SHROP_SETINFO:
goto decode_error;
break;
case SMB_SHROP_LIST:
goto decode_error;
break;
case SMB_SHROP_ENUM:
goto decode_error;
}
if (rc == NERR_Success) {
}
break;
default:
goto decode_error;
}
}
return;
}
/*
* smb_share_dsrv_enum
*
* This function builds a response for a NetShareEnum RAP request which
* originates from smbsrv kernel module. A response buffer is allocated
* with the specified size in esi->es_bufsize. List of shares is scanned
* twice. In the first round the total number of shares which their OEM
* name is shorter than 13 chars (esi->es_ntotal) and also the number of
* shares that fit in the given buffer are calculated. In the second
* round the shares data are encoded in the buffer.
*
* The data associated with each share has two parts, a fixed size part and
* a variable size part which is share's comment. The outline of the response
* buffer is so that fixed part for all the shares will appear first and follows
* with the comments for all those shares and that's why the data cannot be
* encoded in one round without unnecessarily complicating the code.
*/
static int
{
int remained;
return (NERR_InternalError);
/* Do the necessary calculations in the first round */
continue;
else
continue;
}
if (remained <= 0)
continue;
}
}
/* Encode the data in the second round */
continue;
else
continue;
}
break;
break;
}
return (NERR_Success);
}