summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdhcpsvc/modules/binfiles/general.c
blob: 44702471b1df01f76a66f98c8e6e0213f8485fbd (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
/*
 * 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 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.
 */

#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 "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;

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 *directory)
{
	if (mkdirp(directory, 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);
}