4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include "ldap_common.h"
29 #include <sys/tsol/tndb.h>
31 /* tnrhtp attributes filters */
32 #define _TNRHTP_NAME "ipTnetTemplateName"
33 #define _TNRHTP_ATTRS "SolarisAttrKeyValue"
34 #define _F_GETTNTPBYNAME "(&(objectClass=ipTnetTemplate)"\
35 "(!(objectClass=ipTnetHost))" \
36 "(ipTnetTemplateName=%s))"
37 #define _F_GETTNTPBYNAME_SSD "(&(%%s)(ipTnetTemplateName=%s))"
39 static const char *tnrhtp_attrs
[] = {
46 * _nss_ldap_tnrhtp2str is the data marshaling method for the tnrhtp
47 * (tsol_gettpbyaddr()/tsol_gettpent()) backend processes.
48 * This method is called after a successful ldap search has been performed.
49 * This method will parse the ldap search values into the file format.
53 * admin_low:host_type=unlabeled;def_label=[0x0000000000000000000000000000000000
54 * 0000000000000000000000000000000000];min_sl=0x00000000000000000000000000000000
55 * 000000000000000000000000000000000000;max_sl=0x7ffffffffffffffffffffffffffffff
56 * fffffffffffffffffffffffffffffffffffff;doi=0;
59 _nss_ldap_tnrhtp2str(ldap_backend_ptr be
, nss_XbyY_args_t
*argp
)
61 int nss_result
= NSS_STR_PARSE_SUCCESS
;
64 char **attrs
, **template;
65 ns_ldap_result_t
*result
= be
->result
;
68 return (NSS_STR_PARSE_PARSE
);
70 template = __ns_ldap_getAttr(result
->entry
, _TNRHTP_NAME
);
71 if (template == NULL
|| template[0] == NULL
||
72 (strlen(template[0]) < 1)) {
73 nss_result
= NSS_STR_PARSE_PARSE
;
74 goto result_tnrhtp2str
;
76 attrs
= __ns_ldap_getAttr(result
->entry
, _TNRHTP_ATTRS
);
77 if (attrs
== NULL
|| attrs
[0] == NULL
|| (strlen(attrs
[0]) < 1)) {
78 nss_result
= NSS_STR_PARSE_PARSE
;
79 goto result_tnrhtp2str
;
82 /* "template:attrs" */
83 len
= strlen(template[0]) + strlen(attrs
[0]) + 2;
85 if (argp
->buf
.result
!= NULL
) {
86 if ((be
->buffer
= calloc(1, len
)) == NULL
) {
87 nss_result
= NSS_STR_PARSE_PARSE
;
88 goto result_tnrhtp2str
;
93 buffer
= argp
->buf
.buffer
;
95 (void) snprintf(buffer
, len
, "%s:%s", template[0], attrs
[0]);
98 (void) __ns_ldap_freeResult(&be
->result
);
103 getbyname(ldap_backend_ptr be
, void *a
)
105 char searchfilter
[SEARCHFILTERLEN
];
106 char userdata
[SEARCHFILTERLEN
];
107 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
109 if (argp
->key
.name
== NULL
)
110 return (NSS_NOTFOUND
);
112 if (snprintf(searchfilter
, SEARCHFILTERLEN
, _F_GETTNTPBYNAME
,
114 return ((nss_status_t
)NSS_NOTFOUND
);
116 if (snprintf(userdata
, sizeof (userdata
), _F_GETTNTPBYNAME_SSD
,
118 return ((nss_status_t
)NSS_NOTFOUND
);
120 return (_nss_ldap_lookup(be
, argp
, _TNRHTP
, searchfilter
, NULL
,
121 _merge_SSD_filter
, userdata
));
125 static ldap_backend_op_t tnrhtp_ops
[] = {
135 _nss_ldap_tnrhtp_constr(const char *dummy1
,
141 return ((nss_backend_t
*)_nss_ldap_constr(tnrhtp_ops
,
142 sizeof (tnrhtp_ops
)/sizeof (tnrhtp_ops
[0]), _TNRHTP
,
143 tnrhtp_attrs
, _nss_ldap_tnrhtp2str
));