xref: /onnv-gate/usr/src/lib/nsswitch/ad/common/getspent.c (revision 12914:e95332bf1454)
18040SBaban.Kenkre@Sun.COM /*
28040SBaban.Kenkre@Sun.COM  * CDDL HEADER START
38040SBaban.Kenkre@Sun.COM  *
48040SBaban.Kenkre@Sun.COM  * The contents of this file are subject to the terms of the
58040SBaban.Kenkre@Sun.COM  * Common Development and Distribution License (the "License").
68040SBaban.Kenkre@Sun.COM  * You may not use this file except in compliance with the License.
78040SBaban.Kenkre@Sun.COM  *
88040SBaban.Kenkre@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98040SBaban.Kenkre@Sun.COM  * or http://www.opensolaris.org/os/licensing.
108040SBaban.Kenkre@Sun.COM  * See the License for the specific language governing permissions
118040SBaban.Kenkre@Sun.COM  * and limitations under the License.
128040SBaban.Kenkre@Sun.COM  *
138040SBaban.Kenkre@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
148040SBaban.Kenkre@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158040SBaban.Kenkre@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
168040SBaban.Kenkre@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
178040SBaban.Kenkre@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
188040SBaban.Kenkre@Sun.COM  *
198040SBaban.Kenkre@Sun.COM  * CDDL HEADER END
208040SBaban.Kenkre@Sun.COM  */
218040SBaban.Kenkre@Sun.COM /*
22*12914SJoyce.McIntosh@Sun.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
238040SBaban.Kenkre@Sun.COM  */
248040SBaban.Kenkre@Sun.COM 
258040SBaban.Kenkre@Sun.COM #include <shadow.h>
268040SBaban.Kenkre@Sun.COM #include <stdlib.h>
278040SBaban.Kenkre@Sun.COM #include "ad_common.h"
288040SBaban.Kenkre@Sun.COM 
298040SBaban.Kenkre@Sun.COM static int
update_buffer(ad_backend_ptr be,nss_XbyY_args_t * argp,const char * name,const char * domain)308040SBaban.Kenkre@Sun.COM update_buffer(ad_backend_ptr be, nss_XbyY_args_t *argp,
318040SBaban.Kenkre@Sun.COM 		const char *name, const char *domain)
328040SBaban.Kenkre@Sun.COM {
338040SBaban.Kenkre@Sun.COM 	int	buflen;
348040SBaban.Kenkre@Sun.COM 	char	*buffer;
358040SBaban.Kenkre@Sun.COM 
368040SBaban.Kenkre@Sun.COM 	/*
378040SBaban.Kenkre@Sun.COM 	 * The user password is not available in the AD object and therefore
388040SBaban.Kenkre@Sun.COM 	 * sp_pwdp will be "*NP*".
398040SBaban.Kenkre@Sun.COM 	 *
408040SBaban.Kenkre@Sun.COM 	 * nss_ad will leave aging fields empty (i.e. The front end
418040SBaban.Kenkre@Sun.COM 	 * marshaller will set sp_lstchgst, sp_min, sp_max, sp_warn,
428040SBaban.Kenkre@Sun.COM 	 * sp_inact, and sp_expire to -1 and sp_flag to 0) because shadow
438040SBaban.Kenkre@Sun.COM 	 * fields are irrevalent with AD and krb5.
448040SBaban.Kenkre@Sun.COM 	 */
458040SBaban.Kenkre@Sun.COM 
468040SBaban.Kenkre@Sun.COM 	buflen = snprintf(NULL, 0, "%s@%s:*NP*:::::::", name, domain) + 1;
478040SBaban.Kenkre@Sun.COM 
488040SBaban.Kenkre@Sun.COM 	if (argp->buf.result != NULL) {
498040SBaban.Kenkre@Sun.COM 		buffer = be->buffer = malloc(buflen);
508040SBaban.Kenkre@Sun.COM 		if (be->buffer == NULL)
518040SBaban.Kenkre@Sun.COM 			return (-1);
528040SBaban.Kenkre@Sun.COM 		be->buflen = buflen;
538040SBaban.Kenkre@Sun.COM 	} else {
548040SBaban.Kenkre@Sun.COM 		if (buflen > argp->buf.buflen)
558040SBaban.Kenkre@Sun.COM 			return (-1);
568040SBaban.Kenkre@Sun.COM 		buflen = argp->buf.buflen;
578040SBaban.Kenkre@Sun.COM 		buffer = argp->buf.buffer;
588040SBaban.Kenkre@Sun.COM 	}
598040SBaban.Kenkre@Sun.COM 
608040SBaban.Kenkre@Sun.COM 	buflen = snprintf(buffer, buflen, "%s@%s:*NP*:::::::",
618040SBaban.Kenkre@Sun.COM 	    name, domain) + 1;
628040SBaban.Kenkre@Sun.COM 	return (0);
638040SBaban.Kenkre@Sun.COM }
648040SBaban.Kenkre@Sun.COM 
658040SBaban.Kenkre@Sun.COM /*
668040SBaban.Kenkre@Sun.COM  * getbynam gets a shadow entry by winname. This function constructs an ldap
678040SBaban.Kenkre@Sun.COM  * search filter using the name invocation parameter and the getspnam search
688040SBaban.Kenkre@Sun.COM  * filter defined. Once the filter is constructed we search for a matching
698040SBaban.Kenkre@Sun.COM  * entry and marshal the data results into struct shadow for the frontend
708040SBaban.Kenkre@Sun.COM  * process. The function _nss_ad_shadow2ent performs the data marshaling.
718040SBaban.Kenkre@Sun.COM  */
728040SBaban.Kenkre@Sun.COM static nss_status_t
getbynam(ad_backend_ptr be,void * a)738040SBaban.Kenkre@Sun.COM getbynam(ad_backend_ptr be, void *a)
748040SBaban.Kenkre@Sun.COM {
758040SBaban.Kenkre@Sun.COM 	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
768040SBaban.Kenkre@Sun.COM 	char		name[SEARCHFILTERLEN + 1];
778040SBaban.Kenkre@Sun.COM 	char		*dname;
788040SBaban.Kenkre@Sun.COM 	nss_status_t	stat;
798040SBaban.Kenkre@Sun.COM 	idmap_stat	idmaprc;
808040SBaban.Kenkre@Sun.COM 	uid_t		uid;
818040SBaban.Kenkre@Sun.COM 	int		is_user, is_wuser;
828040SBaban.Kenkre@Sun.COM 
838040SBaban.Kenkre@Sun.COM 	be->db_type = NSS_AD_DB_SHADOW_BYNAME;
848040SBaban.Kenkre@Sun.COM 
858040SBaban.Kenkre@Sun.COM 	/* Sanitize name so that it can be used in our LDAP filter */
868040SBaban.Kenkre@Sun.COM 	if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0)
878040SBaban.Kenkre@Sun.COM 		return ((nss_status_t)NSS_NOTFOUND);
888040SBaban.Kenkre@Sun.COM 
898040SBaban.Kenkre@Sun.COM 	if ((dname = strchr(name, '@')) == NULL)
908040SBaban.Kenkre@Sun.COM 		return ((nss_status_t)NSS_NOTFOUND);
918040SBaban.Kenkre@Sun.COM 
928040SBaban.Kenkre@Sun.COM 	*dname = '\0';
938040SBaban.Kenkre@Sun.COM 	dname++;
948040SBaban.Kenkre@Sun.COM 
958040SBaban.Kenkre@Sun.COM 	/*
968040SBaban.Kenkre@Sun.COM 	 * Use idmap service to verify that the given
978040SBaban.Kenkre@Sun.COM 	 * name is a valid Windows name.
988040SBaban.Kenkre@Sun.COM 	 */
998040SBaban.Kenkre@Sun.COM 	is_wuser = -1;
1008040SBaban.Kenkre@Sun.COM 	is_user = 1;
101*12914SJoyce.McIntosh@Sun.COM 	idmaprc = idmap_get_w2u_mapping(NULL, NULL, name, dname,
1028040SBaban.Kenkre@Sun.COM 	    0, &is_user, &is_wuser, &uid, NULL, NULL, NULL);
1038040SBaban.Kenkre@Sun.COM 	if (idmaprc != IDMAP_SUCCESS) {
1048040SBaban.Kenkre@Sun.COM 		RESET_ERRNO();
1058040SBaban.Kenkre@Sun.COM 		return ((nss_status_t)NSS_NOTFOUND);
1068040SBaban.Kenkre@Sun.COM 	}
1078040SBaban.Kenkre@Sun.COM 
1088040SBaban.Kenkre@Sun.COM 	/* Create shadow(4) style string */
1098040SBaban.Kenkre@Sun.COM 	if (update_buffer(be, argp, name, dname) < 0)
1108040SBaban.Kenkre@Sun.COM 		return ((nss_status_t)NSS_NOTFOUND);
1118040SBaban.Kenkre@Sun.COM 
1128040SBaban.Kenkre@Sun.COM 	/* Marshall the data, sanitize the return status and return */
1138040SBaban.Kenkre@Sun.COM 	stat = _nss_ad_marshall_data(be, argp);
1148040SBaban.Kenkre@Sun.COM 	return (_nss_ad_sanitize_status(be, argp, stat));
1158040SBaban.Kenkre@Sun.COM }
1168040SBaban.Kenkre@Sun.COM 
1178040SBaban.Kenkre@Sun.COM static ad_backend_op_t sp_ops[] = {
1188040SBaban.Kenkre@Sun.COM     _nss_ad_destr,
1198040SBaban.Kenkre@Sun.COM     _nss_ad_endent,
1208040SBaban.Kenkre@Sun.COM     _nss_ad_setent,
1218040SBaban.Kenkre@Sun.COM     _nss_ad_getent,
1228040SBaban.Kenkre@Sun.COM     getbynam
1238040SBaban.Kenkre@Sun.COM };
1248040SBaban.Kenkre@Sun.COM 
1258040SBaban.Kenkre@Sun.COM 
1268040SBaban.Kenkre@Sun.COM /*
1278040SBaban.Kenkre@Sun.COM  * _nss_ad_passwd_constr is where life begins. This function calls the
1288040SBaban.Kenkre@Sun.COM  * generic ldap constructor function to define and build the abstract
1298040SBaban.Kenkre@Sun.COM  * data types required to support ldap operations.
1308040SBaban.Kenkre@Sun.COM  */
1318040SBaban.Kenkre@Sun.COM /*ARGSUSED0*/
1328040SBaban.Kenkre@Sun.COM nss_backend_t *
_nss_ad_shadow_constr(const char * dummy1,const char * dummy2,const char * dummy3)1338040SBaban.Kenkre@Sun.COM _nss_ad_shadow_constr(const char *dummy1, const char *dummy2,
1348040SBaban.Kenkre@Sun.COM 			const char *dummy3)
1358040SBaban.Kenkre@Sun.COM {
1368040SBaban.Kenkre@Sun.COM 
1378040SBaban.Kenkre@Sun.COM 	return ((nss_backend_t *)_nss_ad_constr(sp_ops,
1388040SBaban.Kenkre@Sun.COM 	    sizeof (sp_ops)/sizeof (sp_ops[0]),
1398040SBaban.Kenkre@Sun.COM 	    _SHADOW, NULL, NULL));
1408040SBaban.Kenkre@Sun.COM }
141