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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * DESCRIPTION: Contains helper functions for N2L
34 * Includes. WE WANT TO USE REAL DBM FUNCTIONS SO DO NOT INCLUDE SHIM_HOOKS.H.
39 #include <sys/systeminfo.h>
47 #include "../ldap_util.h"
49 /* Enable standard YP code features defined in ypdefs.h */
61 * FUNCTION : alloc_temp_names()
63 * DESCRIPTION: Creates the set of temporary names for update files. It is
64 * the caller responsibility to free these.
66 * GIVEN : Name of map (fully qualified)
68 * RETURNS : SUCCESS with all names allocated.
69 * FAILURE with no names allocated.
72 alloc_temp_names(char *name
, char **temp_entries
, char **temp_ttl
)
74 char *myself
= "alloc_temp_names";
76 *temp_entries
= (char *)am(myself
, strlen(name
) +
77 strlen(TEMP_POSTFIX
) + 1);
78 if (NULL
== *temp_entries
) {
82 *temp_ttl
= (char *)am(myself
, strlen(TEMP_POSTFIX
) + strlen(name
) +
83 strlen(TTL_POSTFIX
) + 1);
84 if (NULL
== *temp_ttl
) {
89 strcpy(*temp_entries
, name
);
90 strcat(*temp_entries
, TEMP_POSTFIX
);
92 strcpy(*temp_ttl
, name
);
93 strcat(*temp_ttl
, TTL_POSTFIX
);
94 strcat(*temp_ttl
, TEMP_POSTFIX
);
100 * FUNCTION : addpair()
102 * DESCRIPTION: Adds a single string entry to a dbm database. This is a copy of
103 * a function from makedbm but is useful enough to be put into
106 * GIVEN: Database handle
110 * RETURNS : SUCCESS = Value written
111 * FAILURE = Value not written.
114 addpair(DBM
*fdb
, char *str1
, char *str2
)
120 key
.dsize
= strlen(str1
);
122 content
.dsize
= strlen(str2
);
124 if (dbm_store(fdb
, key
, content
, DBM_REPLACE
) != 0) {
125 logmsg(MSG_NOTIMECHECK
, LOG_ERR
, "Problem storing %.*s %.*s "
127 key
.dptr
, content
.dptr
, errno
);
134 * FUNCTION : dump_datum()
136 * DESCRIPTION: Prints out a datum as a text string with no line feed.
139 dump_datum(datum
*dat
)
144 printf("NULL datum");
148 if (NULL
== dat
->dptr
) {
152 for (i
= 0; i
< dat
->dsize
; i
++)
153 putchar(dat
->dptr
[i
]);
157 * FUNCTION : update_timestamp()
159 * DESCRIPTION: Adds, or updates, a maps last modified timestamp.
161 * GIVEN : Pointer to an open DBM file.
163 * RETURNS : SUCCESS = Entry created
164 * FAILURE = Entry not created
167 update_timestamp(DBM
*db
)
169 char time_string
[MAX_ASCII_ORDER_NUMBER_LENGTH
];
172 if (0 != gettimeofday(&now
, NULL
)) {
173 logmsg(MSG_NOTIMECHECK
, LOG_ERR
, "Could not get time of day");
176 sprintf(time_string
, "%010ld", (long)now
.tv_sec
);
177 if (SUCCESS
!= addpair(db
, yp_last_modified
, time_string
))