rcfile.c revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce
/*
* Copyright (c) 2000, Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: rcfile.c,v 1.1.1.2 2001/07/06 22:38:43 conrad Exp $
*/
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <synch.h>
#include <unistd.h>
#include <pwd.h>
#include <libintl.h>
#include <cflib.h>
#include "rcfile_priv.h"
#include <assert.h>
#if 0 /* before SMF */
#define SMB_CFG_FILE "/etc/nsmb.conf"
#define OLD_SMB_CFG_FILE "/usr/local/etc/nsmb.conf"
#endif
#define SMBFS_SHARECTL_CMD "/usr/sbin/sharectl get smbfs"
extern int smb_debug;
const char *value);
static void rc_key_free(struct rckey *p);
/* lock for the variables below */
int home_nsmbrc;
int insecure_nsmbrc;
/*
* open rcfile and load its content, if already open - return previous handle
*/
static int
{
FILE *f;
if (rcp) {
return (0);
}
if (f == NULL)
return (errno);
insecure_nsmbrc = 0;
insecure_nsmbrc = 1;
fclose(f);
return (ENOMEM);
}
return (0);
}
static int
{
FILE *f, *t;
insecure_nsmbrc = 0;
}
if (f == NULL)
return (errno);
insecure_nsmbrc = 0;
insecure_nsmbrc = 1;
fclose(f);
return (0);
}
/*
* Like rc_open, but does popen of command:
* sharectl get smbfs
*/
static int
{
FILE *f;
if (f == NULL)
return (errno);
insecure_nsmbrc = 0;
fclose(f);
return (ENOMEM);
}
/* fclose(f) in rc_close */
return (0);
}
static int
{
struct rcsection *p, *n;
n = p;
p = SLIST_NEXT(p, rs_next);
rc_freesect(rcp, n);
}
return (0);
}
static struct rcfile *
rc_cachelookup(const char *filename)
{
struct rcfile *p;
return (p);
return (0);
}
static struct rcsection *
{
struct rcsection *p;
return (p);
return (NULL);
}
static struct rcsection *
{
struct rcsection *p;
if (p)
return (p);
p = malloc(sizeof (*p));
if (!p)
return (NULL);
SLIST_INIT(&p->rs_keys);
return (p);
}
static int
{
struct rckey *p, *n;
n = p;
p = SLIST_NEXT(p, rk_next);
rc_key_free(n);
}
return (0);
}
static struct rckey *
{
struct rckey *p;
return (p);
return (NULL);
}
static struct rckey *
{
struct rckey *p;
if (!p) {
p = malloc(sizeof (*p));
if (!p)
return (NULL);
}
return (p);
}
#if 0
void
{
rc_key_free(p);
}
#endif
static void
rc_key_free(struct rckey *p)
{
free(p);
}
static char *minauth_values[] = {
"none",
"lm",
"ntlm",
"ntlmv2",
"kerberos",
};
static int
eval_minauth(char *auth)
{
int i;
for (i = 0; minauth_values[i]; i++)
return (i);
return (-1);
}
/*
* Ensure that "minauth" is set to the highest level
*/
/*ARGSUSED*/
static void
char *ptr)
{
#ifdef DEBUG
char *from;
if (smb_debug)
from = (home_nsmbrc) ?
"user file" : "SMF";
#endif
#ifdef DEBUG
if (smb_debug)
"set_value: rejecting %s=%s"
" in %s from %s\n",
#endif
return;
}
}
#ifdef DEBUG
if (smb_debug)
"set_value: applying %s=%s in %s from %s\n",
#endif
}
/* states in rc_parse */
static void
{
char buf[2048];
if (c == '\r')
continue;
if (isspace(c))
continue; /* skip leading junk */
if (c == '[') {
continue;
}
if (c == '#' || c == ';') {
state = stSkipToEOL;
} else { /* something meaningfull */
}
}
/* ignore long lines */
if (c == '\n') {
}
continue;
}
if (c == ']') {
*next = 0;
state = stSkipToEOL;
} else
*next++ = c;
continue;
}
/* side effect: 'key name=' */
if (c == ' ' || c == '\t')
continue; /* become 'keyname=' */
if (c == '\n') { /* silently ignore ... */
continue;
}
if (c != '=') {
*next++ = c;
continue;
}
*next = 0;
"Key '%s' defined before section\n"), buf);
state = stSkipToEOL;
continue;
}
if (home_nsmbrc != 0 && (
"option %s may not be set "
"in user .nsmbrc file\n"), buf);
continue;
}
if (insecure_nsmbrc != 0 &&
"Warning: .nsmbrc file not secure, "
"ignoring passwords\n"));
continue;
}
state = stGetValue;
continue;
}
/* only stGetValue left */
if (state != stGetValue) {
state = stSkipToEOL;
}
if (c != '\n') {
*next++ = c;
continue;
}
*next = 0;
} /* while */
*next = 0;
}
}
int
char **dest)
{
int err;
if (!rsp) {
goto out;
}
if (!rkp) {
goto out;
}
err = 0;
out:
return (err);
}
int
{
char *value;
int error;
if (error)
return (error);
"line too long for key '%s' in section '%s', max = %d\n"),
return (EINVAL);
}
return (0);
}
int
{
int err;
if (!rsp) {
goto out;
}
if (!rkp) {
goto out;
}
errno = 0;
"invalid int value '%s' for key '%s' in section '%s'\n"),
}
out:
return (err);
}
/*
* 1,yes,true
* 0,no,false
*/
int
{
char *p;
int err;
if (!rsp) {
goto out;
}
if (!rkp) {
goto out;
}
while (*p && isspace(*p)) p++;
if (*p == '0' ||
strcasecmp(p, "no") == 0 ||
strcasecmp(p, "false") == 0) {
*value = 0;
err = 0;
goto out;
}
if (*p == '1' ||
strcasecmp(p, "yes") == 0 ||
strcasecmp(p, "true") == 0) {
*value = 1;
err = 0;
goto out;
}
"invalid boolean value '%s' for key '%s' in section '%s' \n"),
out:
return (err);
}
#ifdef DEBUG
void
dump_props(char *where)
{
}
}
}
#endif
/*
* first parse "sharectl get smbfs, then $HOME/.nsmbrc
* This is called by library consumers (commands)
*/
int
smb_open_rcfile(char *home)
{
char *fn;
#if 0 /* before SMF */
fn = SMB_CFG_FILE;
#else
#endif
/* Error from fopen. strerror is OK. */
}
#ifdef DEBUG
if (smb_debug)
dump_props(fn);
#endif
if (home) {
home_nsmbrc = 1;
}
home_nsmbrc = 0;
#ifdef DEBUG
if (smb_debug)
dump_props(fn);
#endif
}
/* Mostly ignore error returns above. */
else
error = 0;
return (error);
}
/*
* This is called by library consumers (commands)
*/
void
smb_close_rcfile(void)
{
}
}