plugin.c revision 0fd7766084e66e6e9fda9eb800b67bbf965d4bff
/*
* 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"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libshare.h>
#include "libshare_impl.h"
#include <dlfcn.h>
#include <link.h>
#include <dirent.h>
#include <libintl.h>
#include <sys/systeminfo.h>
#include <thread.h>
#include <synch.h>
/*
* protocol plugin interface
*
* finds plugins and makes them accessible. This is only "used" by
* libshare.so.
*/
struct sa_proto_plugin *sap_proto_list;
static struct sa_proto_handle sa_proto_handle;
void proto_plugin_fini();
/*
* proto_plugin_init()
*
* Initialize the protocol specific plugin modules.
*
* /usr/lib/fs/nfs/libshare_nfs.so. The protocol specific directory
* would have a modules with name libshare_<proto>.so. If one is
* found, initialize it and add to the internal list of
* protocols. These are used for protocol specific operations.
*/
int
{
struct sa_proto_plugin *proto;
int num_protos = 0;
struct sa_plugin_ops *plugin_ops;
void *dlhandle;
/*
* libshare_*.so
*/
char path[MAXPATHLEN];
#if defined(_LP64)
isa[0] = '\0';
#else
isa[0] = '\0';
#endif
"%s/%s/%s/libshare_%s.so.1", SA_LIB_DIR,
/*
* If file doesn't exist, don't try to map it
*/
continue;
plugin_ops = (struct sa_plugin_ops *)
proto = (struct sa_proto_plugin *)
num_protos++;
} else {
ret = SA_NO_MEMORY;
/* Don't leak a dlhandle */
break;
}
} else {
"Error in plugin for protocol %s: %s\n"),
}
}
}
(char **)calloc(num_protos, sizeof (char *));
sizeof (struct sa_plugin_ops *));
int i;
struct sa_proto_plugin *tmp;
for (i = 0, tmp = sap_proto_list;
int err;
/*
* Only include if the init
* succeeded or was NULL
*/
sa_proto_handle.sa_ops[i] =
sa_proto_handle.sa_proto[i] =
i++;
}
}
} else {
ret = SA_NO_MEMORY;
}
}
/*
* There was an error, so cleanup prior to return of failure.
*/
return (ret);
}
/*
* proto_plugin_fini()
*
* Uninitialize all the plugin modules.
*/
void
{
struct sa_proto_plugin *p;
/*
* Protocols may call this framework during _fini
* (the smbfs plugin is known to do this) so do
* two passes: 1st call _fini; 2nd free, dlclose.
*/
p->plugin_ops->sa_fini();
while ((p = sap_proto_list) != NULL) {
sap_proto_list = p->plugin_next;
if (p->plugin_handle != NULL)
(void) dlclose(p->plugin_handle);
free(p);
}
}
}
}
/*
* find_protocol(proto)
*
* Search the plugin list for the specified protocol and return the
* ops vector. NULL if protocol is not defined.
*/
static struct sa_plugin_ops *
find_protocol(char *proto)
{
int i;
extern mutex_t sa_global_lock;
(void) mutex_lock(&sa_global_lock);
for (i = 0; i < sa_proto_handle.sa_num_proto; i++) {
break;
}
}
}
(void) mutex_unlock(&sa_global_lock);
return (ops);
}
/*
* sa_proto_share(proto, share)
*
* Activate a share for the specified protocol.
*/
int
{
int ret = SA_INVALID_PROTOCOL;
return (ret);
}
/*
* sa_proto_unshare(proto, share)
*
* Deactivate (unshare) the share for this protocol.
*/
int
{
int ret = SA_INVALID_PROTOCOL;
return (ret);
}
/*
* sa_proto_share_resource(char *proto, sa_resource_t resource)
*
* For protocols that actually enable at the resource level, do the
* protocol specific resource enable. If it doesn't, return an error.
* Note that the resource functions are optional so can return
* SA_NOT_SUPPORTED.
*/
int
{
int ret = SA_INVALID_PROTOCOL;
else
}
return (ret);
}
/*
* sa_proto_unshare_resource(char *proto, sa_resource_t resource)
*
* For protocols that actually disable at the resource level, do the
* protocol specific resource disable. If it doesn't, return an error.
*/
int
{
int ret = SA_INVALID_PROTOCOL;
else
}
return (ret);
}
/*
* sa_proto_valid_prop(handle, proto, prop, opt)
*
* Check to see if the specified prop is valid for this protocol.
*/
int
{
int ret = 0;
return (ret);
}
/*
* sa_proto_valid_space(proto, space)
*
* Check if space is valid optionspace for proto.
* Protocols that don't implement this don't support spaces.
*/
int
{
int ret = 0;
return (ret);
}
/*
* sa_proto_space_alias(proto, space)
*
* If the name for space is an alias, return its proper name. This is
* used to translate "default" values into proper form.
*/
char *
{
return (ret);
}
/*
* sa_proto_security_prop(proto, token)
*
* Check to see if the property name in token is a valid named
* optionset property.
*/
int
{
int ret = 0;
return (ret);
}
/*
* sa_proto_legacy_opts(proto, grouup, options)
*
* Have the protocol specific parser parse the options string and add
* an appropriate optionset to group.
*/
int
{
int ret = SA_INVALID_PROTOCOL;
return (ret);
}
/*
* sa_proto_legacy_format(proto, group, hier)
*
* Return a legacy format string representing either the group's
* properties or the groups hierarchical properties.
*/
char *
{
return (ret);
}
void
sa_format_free(char *str)
{
}
/*
* sharectl related API functions
*/
/*
* sa_proto_get_properties(proto)
*
* Return the set of properties that are specific to the
* but only the protocol module knows which ones for sure.
*/
sa_proto_get_properties(char *proto)
{
return (props);
}
/*
* sa_proto_set_property(proto, prop)
*
* Update the protocol specific property.
*/
int
{
return (ret);
}
/*
* sa_valid_protocol(proto)
*
* Check to see if the protocol specified is defined by a
* plugin. Returns true (1) or false (0)
*/
int
sa_valid_protocol(char *proto)
{
}
/*
* Return the current operational status of the protocol
*/
char *
sa_get_protocol_status(char *proto)
{
return (ret);
}
/*
* sa_proto_update_legacy(proto, share)
*
* Update the protocol specific legacy files if necessary for the
* specified share.
*/
int
{
int ret = SA_NOT_IMPLEMENTED;
}
return (ret);
}
/*
* sa_delete_legacy(proto, share)
*
* Remove the specified share from the protocol specific legacy files.
*/
int
{
int ret = SA_NOT_IMPLEMENTED;
} else {
else
}
return (ret);
}
/*
* sa_proto_delete_section(proto, section)
*
* Remove the specified section from the protocol specific legacy files,
* if supported.
*/
int
{
} else {
else
}
return (ret);
}
/*
* sa_proto_change_notify(share, char *protocol)
*
* Notify the protocol that a change has been made to the share
*/
int
{
int ret = SA_NOT_IMPLEMENTED;
}
return (ret);
}
/*
* sa_proto_notify_resource(resource, char *protocol)
*
* Notify the protocol that a change has been made to the share
*/
int
{
int ret = SA_NOT_IMPLEMENTED;
}
return (ret);
}
/*
* sa_proto_get_featureset(protocol)
*
* Get bitmask of defined features of the protocol. These are
* primarily things like SA_FEATURE_RESOURCE (shares are by resource
* name rather than path) and other operational features that affect
* behavior.
*/
sa_proto_get_featureset(char *proto)
{
}
/* if not implemented, zero is valid */
return (ret);
}
/*
* sa_proto_get_transients(sa_handle_t)
*
* Called to get any protocol specific transient shares. NFS doesn't
* use this since the info is in sharetab which is processed as a
* common transient store.
*
* The protocol plugin should verify that the share isn't in the
* repository and then add it as a transient.
*
* Not having an entry is not a problem. It returns 0 in that case.
*/
int
{
int ret = 0;
}
return (ret);
}
/*
* sa_proto_rename_resource(sa_handle_t, proto, sa_resource_t, newname)
*
* Protocols may need to know when a resource has changed names in
* order to notify clients. This must be done "before" the name in the
* resource has been changed. Not being implemented is not a problem.
*/
int
{
newname);
}
return (ret);
}