rcfile.c revision 4bff34e37def8a90f9194d81bc345c52ba20086a
/*
* 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 $
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <libintl.h>
#include <pwd.h>
#include <unistd.h>
#include <cflib.h>
#include "rcfile_priv.h"
const char *value);
static void rc_key_free(struct rckey *p);
int insecure_nsmbrc;
/*
* open rcfile and load its content, if already open - return previous handle
*/
int
{
FILE *f;
if (rcp) {
return (0);
}
if (f == NULL)
return (errno);
insecure_nsmbrc = 0;
insecure_nsmbrc = 1;
fclose(f);
return (ENOMEM);
}
return (0);
}
int
{
FILE *f, *t;
insecure_nsmbrc = 0;
}
if (f == NULL)
return (errno);
fclose(f);
return (0);
}
int
{
FILE *f, *t;
insecure_nsmbrc = 0;
if (f == NULL)
return (errno);
fclose(f);
return (ENOMEM);
}
} else {
}
fclose(f);
return (0);
}
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);
}
int home_nsmbrc = 0;
static char *minauth[] = {
"kerberos",
"ntlmv2",
"ntlm",
"lm",
"none",
};
static int
eval_minauth(char *auth)
{
int i;
for (i = 0; minauth[i]; i++)
break;
return (i);
}
/*
* Ensure that "minauth" is set to the highest level (lowest array offset)
*/
static void
char *ptr)
{
#ifdef DEBUG
printf("set_value: rejecting %s=%s from %s\n",
#endif
return;
}
}
#ifdef DEBUG
printf("set_value: applying %s=%s from %s\n",
#endif
}
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 &&
"option %s may not be set "
"in user .nsmbrc file\n"), buf);
continue;
}
"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)
{
if (!rsp)
return (ENOENT);
if (!rkp)
return (ENOENT);
return (0);
}
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
{
if (!rsp)
return (ENOENT);
if (!rkp)
return (ENOENT);
errno = 0;
if (errno) {
"invalid int value '%s' for key '%s' in section '%s'\n"),
return (errno);
}
return (0);
}
/*
* 1,yes,true
* 0,no,false
*/
int
{
char *p;
if (!rsp)
return (ENOENT);
if (!rkp)
return (ENOENT);
while (*p && isspace(*p)) p++;
if (*p == '0' ||
strcasecmp(p, "no") == 0 ||
strcasecmp(p, "false") == 0) {
*value = 0;
return (0);
}
if (*p == '1' ||
strcasecmp(p, "yes") == 0 ||
strcasecmp(p, "true") == 0) {
*value = 1;
return (0);
}
"invalid boolean value '%s' for key '%s' in section '%s' \n"),
return (EINVAL);
}
/*
*/
int
{
case OPTARG_STR:
break;
"rc: argument for option '%c' (%s) too long\n"),
return (EINVAL);
}
break;
case OPTARG_BOOL:
break;
if (error)
return (EINVAL);
break;
case OPTARG_INT:
break;
"rc: argument for option '%c' (%s) "
"should be in [%d-%d] range\n"),
return (EINVAL);
}
break;
default:
break;
}
}
return (0);
}
int
{
int len;
continue;
case OPTARG_STR:
if (arg) {
"opt: Argument for option '%c' (%s) too long\n"),
return (EINVAL);
}
}
break;
case OPTARG_BOOL:
break;
case OPTARG_INT:
errno = 0;
if (errno) {
"opt: Invalid integer value for "
"option '%c' (%s).\n"),
return (EINVAL);
}
"opt: Argument for option '%c' (%s) "
"should be in [%d-%d] range\n"),
return (EINVAL);
}
break;
default:
break;
}
break;
}
return (0);
}