xref: /onnv-gate/usr/src/lib/libdhcpsvc/modules/binfiles/general.c (revision 0:68f95e015346)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * This file contains public API functions for module-level tasks.  For the
31  * semantics of these functions, please see the Enterprise DHCP
32  * Architecture Document.
33  */
34 
35 #include <assert.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <libgen.h>
42 #include <errno.h>
43 #include <dhcp_svc_public.h>
44 
45 #include "util.h"
46 
47 /*
48  * This symbol and its value tell the private layer that it must provide
49  * synchronization guarantees via dsvclockd(1M) before calling our *_dn()
50  * and *_dt() methods.  Please see $SRC/lib/libdhcpsvc/private/README.synch
51  */
52 int dsvc_synchtype = DSVC_SYNCH_DSVCD;
53 
54 int
status(const char * location)55 status(const char *location)
56 {
57 	if (location != NULL) {
58 		if (access(location, F_OK|R_OK) == -1) {
59 			if (errno == ENOENT)
60 				return (DSVC_NO_LOCATION);
61 			return (syserr_to_dsvcerr(errno));
62 		}
63 	}
64 	return (DSVC_SUCCESS);
65 }
66 
67 int
version(int * vp)68 version(int *vp)
69 {
70 	*vp = DSVC_PUBLIC_VERSION;
71 	return (DSVC_SUCCESS);
72 }
73 
74 int
mklocation(const char * directory)75 mklocation(const char *directory)
76 {
77 	if (mkdirp(directory, 0755) == -1) {
78 		switch (errno) {
79 		case ENAMETOOLONG:
80 		case ENOTDIR:
81 			return (DSVC_INVAL);
82 
83 		case EEXIST:
84 			return (DSVC_EXISTS);
85 
86 		case EROFS:
87 		case EPERM:
88 		case EACCES:
89 			return (DSVC_ACCESS);
90 
91 		default:
92 			return (DSVC_INTERNAL);
93 		}
94 	}
95 
96 	return (DSVC_SUCCESS);
97 }
98 
99 int
mkloctoken(const char * location,char * token,size_t tokensize)100 mkloctoken(const char *location, char *token, size_t tokensize)
101 {
102 	assert(tokensize >= MAXPATHLEN);
103 	if (realpath(location, token) == NULL)
104 		return (syserr_to_dsvcerr(errno));
105 
106 	return (DSVC_SUCCESS);
107 }
108