/*
* 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.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <pwd.h>
#include <nss_dbdefs.h>
#include <assert.h>
#include <strings.h>
#include <smbsrv/libmlsvc.h>
typedef struct smb_autohome_info {
int lineno;
static char *smb_autohome_keysub(const char *, char *, int);
static smb_autohome_info_t *smb_autohome_getinfo(void);
static smb_autohome_t *smb_autohome_lookup(const char *);
static void smb_autohome_setent(void);
static void smb_autohome_endent(void);
static smb_autohome_t *smb_autohome_getent(const char *);
static void smb_autohome_parse_options(smb_share_t *);
/*
* Add an autohome share. See smb_autohome(4) for details.
*
* If share directory contains backslash path separators, they will
* autohome shares.
*
* We need to serialize calls to smb_autohome_lookup because it
* operates on the global smb_ai structure.
*/
void
{
char *username;
return;
if (IDMAP_ID_IS_EPHEMERAL(uid)) {
} else {
"UID: %u\n", uid);
return;
}
}
if (!smb_isstrlwr(username)) {
(void) smb_strlwr(username);
}
}
}
/*
* Remove an autohome share.
*/
void
{
(void) smb_shr_remove((char *)username);
}
}
/*
* An autohome share is not created if a static share using the same name
* already exists. Autohome shares will be added for each login attempt.
*
* Calling smb_shr_get() may return the first argument in all lower case so
* a copy is passed in instead.
*
* We need to serialize calls to smb_autohome_lookup because it
* operates on the global smb_ai structure.
*/
static int
{
return (NERR_Success);
(void) smb_shr_add(&si);
return (NERR_Success);
}
(void) mutex_lock(&autohome_mutex);
(void) mutex_unlock(&autohome_mutex);
return (NERR_ItemNotFound);
}
(void) mutex_unlock(&autohome_mutex);
return (smb_shr_add(&si));
}
/*
* Search the autohome database for the specified name. The name cannot
* be an empty string or begin with * or +.
* 1. Search the file for the specified name.
* 2. Check for the wildcard rule and, if present, treat it as a match.
* 3. Check for the nsswitch rule and, if present, lookup the name
* via the name services. Note that the nsswitch rule will never
* be applied if the wildcard rule is present.
*
* Returns a pointer to the entry on success or null on failure.
*/
static smb_autohome_t *
{
return (NULL);
return (NULL);
break;
}
break;
}
}
}
continue;
break;
}
break;
}
}
return (ah);
}
/*
* Open or rewind the autohome database.
*/
static void
smb_autohome_setent(void)
{
int rc;
if ((si = smb_autohome_getinfo()) != 0) {
return;
}
return;
if (rc != SMBD_SMF_OK)
return;
return;
}
/*
* Close the autohome database and invalidate the autohome info.
* We can't zero the whole info structure because the application
* should still have access to the data after the file is closed.
*/
static void
smb_autohome_endent(void)
{
if ((si = smb_autohome_getinfo()) != 0) {
}
}
/*
* Return the next entry in the autohome database, opening the file
* if necessary. Returns null on EOF or error.
*
* Note that we are not looking for the specified name. The name is
* only used for key substitution, so that the caller sees the entry
* in expanded form.
*/
static smb_autohome_t *
{
char *bp;
if ((si = smb_autohome_getinfo()) == 0) {
if ((si = smb_autohome_getinfo()) == 0)
return (0);
}
/*
* Find the next non-comment, non-empty line.
* Anything after a # is a comment and can be discarded.
* Discard a newline to avoid it being included in the parsing
* that follows.
* Leading and training whitespace is discarded, and replicated
* whitespace is compressed to simplify the token parsing,
* although strsep() deals with that better than strtok().
*/
do {
return (0);
*bp = '\0';
} while (*bp == '\0');
return (smb_autohome_make_entry(si));
}
/*
* Set up an autohome entry from the line buffer. The line should just
* contain tokens separated by single whitespace. The line format is:
* <username> <home-dir-path> <ADS container>
*/
static smb_autohome_t *
{
char *bp;
int i;
for (i = 0; i < SMB_AUTOHOME_MAXARG; ++i)
for (i = 0; i < SMB_AUTOHOME_MAXARG; ++i) {
do {
break;
break;
}
/*
* Sanity check: the name could be an empty
* string but it can't be a null pointer.
*/
return (0);
}
}
/*
* Substitute the ? and & map keys.
* ? is replaced by the first character of the name
* & is replaced by the whole name.
*/
static char *
{
char *ampersand;
char *tmp;
return (NULL);
*tmp = '\0';
/*
* Substitution characters are not allowed in the key.
*/
return (NULL);
return (0);
}
return (buf);
}
/*
* Get a pointer to the context buffer and validate it.
*/
static smb_autohome_info_t *
smb_autohome_getinfo(void)
{
return (0);
return (si);
return (0);
}
/*
* Parse the options string, which contains a comma separated list of
* name-value pairs. One of the options may be an AD container, which
* is also a comma separated list of name-value pairs. For example,
* dn=ad,dn=sun,dn=com,ou=users
*
* All options other than the AD container will be extracted from
* shr_container and used to set share properties.
* On return, shr_container will contain the AD container string.
*/
static void
{
char **argv;
char **ap;
char *bp;
char *value;
int argc;
int i;
return;
if (*bp == ',')
++argc;
return;
do {
break;
} while (*value == '\0');
break;
}
continue;
}
continue;
}
continue;
}
continue;
}
sizeof (si->shr_access_rw));
continue;
}
sizeof (si->shr_access_ro));
continue;
}
sizeof (si->shr_access_none));
continue;
}
if (separator)
}
}