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 <rpc/rpcent.h>
29 #include "ns_internal.h"
30 #include "ldap_common.h"
32 /* rpc attributes filters */
34 #define _R_NUMBER "oncrpcnumber"
37 #define _F_GETRPCBYNAME "(&(objectClass=oncRpc)(cn=%s))"
38 #define _F_GETRPCBYNAME_SSD "(&(%%s)(cn=%s))"
39 #define _F_GETRPCBYNUMBER "(&(objectClass=oncRpc)(oncRpcNumber=%d))"
40 #define _F_GETRPCBYNUMBER_SSD "(&(%%s)(oncRpcNumber=%d))"
42 static const char *rpc_attrs
[] = {
49 * _nss_ldap_rpc2str is the data marshaling method for the rpc getXbyY
50 * (e.g., getbyname(), getbynumber(), getrpcent()) backend processes.
51 * This method is called after a successful ldap search has been performed.
52 * This method will parse the ldap search values into the file format.
56 * snmp 100122 na.snmp snmp-cmc snmp-synoptics snmp-unisys snmp-utk
59 _nss_ldap_rpc2str(ldap_backend_ptr be
, nss_XbyY_args_t
*argp
)
66 ns_ldap_result_t
*result
= be
->result
;
67 ns_ldap_attr_t
*names
;
71 return (NSS_STR_PARSE_PARSE
);
72 nss_result
= NSS_STR_PARSE_SUCCESS
;
73 (void) memset(argp
->buf
.buffer
, 0, buflen
);
75 buflen
= argp
->buf
.buflen
;
76 if (argp
->buf
.result
!= NULL
) {
77 if ((be
->buffer
= calloc(1, buflen
)) == NULL
) {
78 nss_result
= NSS_STR_PARSE_PARSE
;
83 buffer
= argp
->buf
.buffer
;
86 names
= __ns_ldap_getAttrStruct(result
->entry
, _R_NAME
);
87 if (names
== NULL
|| names
->attrvalue
== NULL
) {
88 nss_result
= NSS_STR_PARSE_PARSE
;
91 /* Get the canonical rpc name */
92 cname
= __s_api_get_canonical_name(result
->entry
, names
, 1);
93 if (cname
== NULL
|| (len
= strlen(cname
)) < 1) {
94 nss_result
= NSS_STR_PARSE_PARSE
;
97 rpcnumber
= __ns_ldap_getAttr(result
->entry
, _R_NUMBER
);
98 if (rpcnumber
== NULL
|| rpcnumber
[0] == NULL
||
99 (len
= strlen(rpcnumber
[0])) < 1) {
100 nss_result
= NSS_STR_PARSE_PARSE
;
103 len
= snprintf(buffer
, buflen
, "%s %s", cname
, rpcnumber
[0]);
104 TEST_AND_ADJUST(len
, buffer
, buflen
, result_rpc2str
);
106 for (i
= 0; i
< names
->value_count
; i
++) {
107 if (names
->attrvalue
[i
] == NULL
) {
108 nss_result
= NSS_STR_PARSE_PARSE
;
111 /* Skip the canonical name */
112 if (strcasecmp(names
->attrvalue
[i
], cname
) != 0) {
113 len
= snprintf(buffer
, buflen
, " %s",
114 names
->attrvalue
[i
]);
115 TEST_AND_ADJUST(len
, buffer
, buflen
, result_rpc2str
);
119 /* The front end marshaller doesn't need to copy trailing nulls */
120 if (argp
->buf
.result
!= NULL
)
121 be
->buflen
= strlen(be
->buffer
);
125 (void) __ns_ldap_freeResult(&be
->result
);
130 * getbyname gets struct rpcent values by rpc name. This function
131 * constructs an ldap search filter using the rpc name invocation
132 * parameter and the getrpcbyname search filter defined. Once the
133 * filter is constructed, we search for a matching entry and marshal
134 * the data results into *rpc = (struct rpcent *)argp->buf.result.
135 * The function _nss_ldap_rpc2ent performs the data marshaling.
139 getbyname(ldap_backend_ptr be
, void *a
)
141 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
142 char searchfilter
[SEARCHFILTERLEN
];
143 char userdata
[SEARCHFILTERLEN
];
144 char name
[SEARCHFILTERLEN
];
147 if (_ldap_filter_name(name
, argp
->key
.name
, sizeof (name
)) != 0)
148 return ((nss_status_t
)NSS_NOTFOUND
);
150 ret
= snprintf(searchfilter
, sizeof (searchfilter
), _F_GETRPCBYNAME
,
152 if (ret
>= sizeof (searchfilter
) || ret
< 0)
153 return ((nss_status_t
)NSS_NOTFOUND
);
155 ret
= snprintf(userdata
, sizeof (userdata
), _F_GETRPCBYNAME_SSD
, name
);
156 if (ret
>= sizeof (userdata
) || ret
< 0)
157 return ((nss_status_t
)NSS_NOTFOUND
);
159 return ((nss_status_t
)_nss_ldap_lookup(be
, argp
, _RPC
, searchfilter
,
160 NULL
, _merge_SSD_filter
, userdata
));
165 * getbynumber gets struct rpcent values by rpc number. This function
166 * constructs an ldap search filter using the rpc number invocation
167 * parameter and the getrpcbynumber search filter defined. Once the
168 * filter is constructed, we search for a matching entry and marshal
169 * the data results into *rpc = (struct rpcent *)argp->buf.result.
170 * The function _nss_ldap_rpc2ent performs the data marshaling.
174 getbynumber(ldap_backend_ptr be
, void *a
)
176 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
177 char searchfilter
[SEARCHFILTERLEN
];
178 char userdata
[SEARCHFILTERLEN
];
181 ret
= snprintf(searchfilter
, sizeof (searchfilter
),
182 _F_GETRPCBYNUMBER
, argp
->key
.number
);
183 if (ret
>= sizeof (searchfilter
) || ret
< 0)
184 return ((nss_status_t
)NSS_NOTFOUND
);
186 ret
= snprintf(userdata
, sizeof (userdata
),
187 _F_GETRPCBYNUMBER_SSD
, argp
->key
.number
);
188 if (ret
>= sizeof (userdata
) || ret
< 0)
189 return ((nss_status_t
)NSS_NOTFOUND
);
191 return ((nss_status_t
)_nss_ldap_lookup(be
, argp
, _RPC
, searchfilter
,
192 NULL
, _merge_SSD_filter
, userdata
));
196 static ldap_backend_op_t rpc_ops
[] = {
207 * _nss_ldap_rpc_constr is where life begins. This function calls the generic
208 * ldap constructor function to define and build the abstract data types
209 * required to support ldap operations.
214 _nss_ldap_rpc_constr(const char *dummy1
, const char *dummy2
,
218 return ((nss_backend_t
*)_nss_ldap_constr(rpc_ops
,
219 sizeof (rpc_ops
)/sizeof (rpc_ops
[0]),
220 _RPC
, rpc_attrs
, _nss_ldap_rpc2str
));