auth.c revision 84225
140040Sjkh/*
240040Sjkh * Simple authentication database handling code.
340040Sjkh *
440040Sjkh * Copyright (c) 1998
540040Sjkh *	Jordan Hubbard.  All rights reserved.
640040Sjkh *
740040Sjkh * Redistribution and use in source and binary forms, with or without
840040Sjkh * modification, are permitted provided that the following conditions
940040Sjkh * are met:
1040040Sjkh * 1. Redistributions of source code must retain the above copyright
1140040Sjkh *    notice, this list of conditions and the following disclaimer,
1240040Sjkh *    verbatim and that no modifications are made prior to this
1340040Sjkh *    point in the file.
1440040Sjkh * 2. Redistributions in binary form must reproduce the above copyright
1540040Sjkh *    notice, this list of conditions and the following disclaimer in the
1640040Sjkh *    documentation and/or other materials provided with the distribution.
1740040Sjkh *
1840040Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1940040Sjkh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2040040Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2140040Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR HIS PETS BE LIABLE
2240040Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2340040Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2440040Sjkh * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
2540040Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2640040Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2740040Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2840040Sjkh * SUCH DAMAGE.
2940040Sjkh */
3040040Sjkh
3184225Sdillon#include <sys/cdefs.h>
3284225Sdillon__FBSDID("$FreeBSD: head/lib/libutil/auth.c 84225 2001-09-30 22:35:07Z dillon $");
3384225Sdillon
3440109Sjkh#include <unistd.h>
3540040Sjkh#include <syslog.h>
3640050Sjkh#include <sys/types.h>
3740109Sjkh#include <paths.h>
3840109Sjkh#include <fcntl.h>
3940040Sjkh#include <libutil.h>
4040040Sjkh
4140040Sjkhstatic properties P;
4240040Sjkh
4340040Sjkhstatic int
4440040Sjkhinitauthconf(const char *path)
4540040Sjkh{
4640109Sjkh    int fd;
4740040Sjkh
4840040Sjkh    if (!P) {
4940109Sjkh	if ((fd = open(path, O_RDONLY)) < 0) {
5040040Sjkh	    syslog(LOG_ERR, "initauthconf: unable to open file: %s", path);
5140040Sjkh	    return 1;
5240040Sjkh	}
5340109Sjkh	P = properties_read(fd);
5440109Sjkh	close(fd);
5540040Sjkh	if (!P) {
5640040Sjkh	    syslog(LOG_ERR, "initauthconf: unable to parse file: %s", path);
5740040Sjkh	    return 1;
5840040Sjkh	}
5940040Sjkh    }
6040040Sjkh    return 0;
6140040Sjkh}
6240040Sjkh
6340040Sjkhchar *
6440040Sjkhauth_getval(const char *name)
6540040Sjkh{
6640040Sjkh    if (!P && initauthconf(_PATH_AUTHCONF))
6740040Sjkh	return NULL;
6840040Sjkh    else
6940040Sjkh	return property_find(P, name);
7040040Sjkh}
71