auth.c revision 116344
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * Simple authentication database handling code.
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * Copyright (c) 1998
50Sstevel@tonic-gate *	Jordan Hubbard.  All rights reserved.
60Sstevel@tonic-gate *
70Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
80Sstevel@tonic-gate * modification, are permitted provided that the following conditions
90Sstevel@tonic-gate * are met:
100Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
110Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer,
120Sstevel@tonic-gate *    verbatim and that no modifications are made prior to this
130Sstevel@tonic-gate *    point in the file.
140Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
150Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
160Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
170Sstevel@tonic-gate *
180Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
190Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
200Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
210Sstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR HIS PETS BE LIABLE
220Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
230Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
240Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
250Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
260Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
270Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
280Sstevel@tonic-gate * SUCH DAMAGE.
290Sstevel@tonic-gate */
300Sstevel@tonic-gate
310Sstevel@tonic-gate#include <sys/cdefs.h>
320Sstevel@tonic-gate__FBSDID("$FreeBSD: head/lib/libutil/auth.c 116344 2003-06-14 18:42:37Z markm $");
330Sstevel@tonic-gate
340Sstevel@tonic-gate#include <sys/types.h>
350Sstevel@tonic-gate#include <fcntl.h>
360Sstevel@tonic-gate#include <libutil.h>
370Sstevel@tonic-gate#include <paths.h>
380Sstevel@tonic-gate#include <syslog.h>
390Sstevel@tonic-gate#include <unistd.h>
400Sstevel@tonic-gate
410Sstevel@tonic-gatestatic properties P;
420Sstevel@tonic-gate
430Sstevel@tonic-gatestatic int
440Sstevel@tonic-gateinitauthconf(const char *path)
450Sstevel@tonic-gate{
460Sstevel@tonic-gate    int fd;
470Sstevel@tonic-gate
480Sstevel@tonic-gate    if (!P) {
490Sstevel@tonic-gate	if ((fd = open(path, O_RDONLY)) < 0) {
500Sstevel@tonic-gate	    syslog(LOG_ERR, "initauthconf: unable to open file: %s", path);
510Sstevel@tonic-gate	    return 1;
520Sstevel@tonic-gate	}
530Sstevel@tonic-gate	P = properties_read(fd);
540Sstevel@tonic-gate	close(fd);
550Sstevel@tonic-gate	if (!P) {
560Sstevel@tonic-gate	    syslog(LOG_ERR, "initauthconf: unable to parse file: %s", path);
570Sstevel@tonic-gate	    return 1;
580Sstevel@tonic-gate	}
590Sstevel@tonic-gate    }
600Sstevel@tonic-gate    return 0;
610Sstevel@tonic-gate}
620Sstevel@tonic-gate
630Sstevel@tonic-gatechar *
640Sstevel@tonic-gateauth_getval(const char *name)
650Sstevel@tonic-gate{
660Sstevel@tonic-gate    if (!P && initauthconf(_PATH_AUTHCONF))
670Sstevel@tonic-gate	return NULL;
680Sstevel@tonic-gate    else
690Sstevel@tonic-gate	return property_find(P, name);
700Sstevel@tonic-gate}
710Sstevel@tonic-gate