summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdhcpsvc/modules/files/general.c
blob: f1987b43ef26eefc96b7f447f6466740a836d79c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (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
 * or http://www.opensolaris.org/os/licensing.
 * 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 (c) 2000-2001 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

/*
 * This file contains public API functions for module-level tasks.  For the
 * semantics of these functions, please see the Enterprise DHCP
 * Architecture Document.
 *
 * WARNING: This file is also compiled into the files0 module; if you make
 *	    changes to this file which are not appropriate for files0, you
 *	    will need to provide files0 with its own implementation.
 */

#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <libgen.h>
#include <errno.h>
#include <dhcp_svc_public.h>
#include <dhcp_svc_private.h>		/* DSVC_SYNCH_CROSSHOST */

#include "util.h"

/*
 * This symbol and its value tell the private layer that it must provide
 * synchronization guarantees via dsvclockd(1M) before calling our *_dn()
 * and *_dt() methods.  Please see $SRC/lib/libdhcpsvc/private/README.synch
 */
int dsvc_synchtype = DSVC_SYNCH_DSVCD | DSVC_SYNCH_CROSSHOST;

int
status(const char *location)
{
	if (location != NULL) {
		if (access(location, F_OK|R_OK) == -1) {
			if (errno == ENOENT)
				return (DSVC_NO_LOCATION);
			return (syserr_to_dsvcerr(errno));
		}
	}
	return (DSVC_SUCCESS);
}

int
version(int *vp)
{
	*vp = DSVC_PUBLIC_VERSION;
	return (DSVC_SUCCESS);
}

int
mklocation(const char *location)
{
	if (mkdirp(location, 0755) == -1) {
		switch (errno) {
		case ENAMETOOLONG:
		case ENOTDIR:
			return (DSVC_INVAL);

		case EEXIST:
			return (DSVC_EXISTS);

		case EROFS:
		case EPERM:
		case EACCES:
			return (DSVC_ACCESS);

		default:
			return (DSVC_INTERNAL);
		}
	}

	return (DSVC_SUCCESS);
}

int
mkloctoken(const char *location, char *token, size_t tokensize)
{
	assert(tokensize >= MAXPATHLEN);
	if (realpath(location, token) == NULL)
		return (syserr_to_dsvcerr(errno));

	return (DSVC_SUCCESS);
}