1 /* pam.c - pam processing routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2008-2015 The OpenLDAP Foundation.
6 * Portions Copyright 2008 by Howard Chu, Symas Corp.
7 * Portions Copyright 2013 by Ted C. Cheng, Symas Corp.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
22 static int ppolicy_cid;
23 static AttributeDescription *ad_loginStatus;
35 static int pam_bindcb(
36 Operation *op, SlapReply *rs)
38 struct paminfo *pi = op->o_callback->sc_private;
39 LDAPControl *ctrl = ldap_control_find(LDAP_CONTROL_PASSWORDPOLICYRESPONSE,
43 ber_int_t expire, grace;
44 LDAPPasswordPolicyError error;
48 int rc = ldap_parse_passwordpolicy_control(ld,ctrl,
49 &expire,&grace,&error);
50 if (rc == LDAP_SUCCESS) {
52 char *unit = "seconds";
65 #if 0 /* Who warns about expiration so far in advance? */
79 pi->msg.bv_len = sprintf(pi->msg.bv_val,
80 "\nWARNING: Password expires in %d %s\n", expire, unit);
81 } else if (grace > 0) {
82 pi->msg.bv_len = sprintf(pi->msg.bv_val,
83 "Password expired; %d grace logins remaining",
85 pi->authz = NSLCD_PAM_NEW_AUTHTOK_REQD;
86 } else if (error != PP_noError) {
87 ber_str2bv(ldap_passwordpolicy_err2txt(error), 0, 0,
90 case PP_passwordExpired:
91 /* report this during authz */
92 rs->sr_err = LDAP_SUCCESS;
94 case PP_changeAfterReset:
95 pi->authz = NSLCD_PAM_NEW_AUTHTOK_REQD;
99 ldap_ld_free(ld,0,NULL,NULL);
105 static int pam_uid2dn(nssov_info *ni, Operation *op,
112 if (!isvalidusername(&pi->uid)) {
113 Debug(LDAP_DEBUG_ANY,"nssov_pam_uid2dn(%s): invalid user name\n",
114 pi->uid.bv_val ? pi->uid.bv_val : "NULL",0,0);
115 return NSLCD_PAM_USER_UNKNOWN;
118 if (ni->ni_pam_opts & NI_PAM_SASL2DN) {
119 int hlen = global_host_bv.bv_len;
121 /* cn=<service>+uid=<user>,cn=<host>,cn=pam,cn=auth */
122 sdn.bv_len = pi->uid.bv_len + pi->svc.bv_len + hlen +
123 STRLENOF( "cn=+uid=,cn=,cn=pam,cn=auth" );
124 sdn.bv_val = op->o_tmpalloc( sdn.bv_len + 1, op->o_tmpmemctx );
125 sprintf(sdn.bv_val, "cn=%s+uid=%s,cn=%s,cn=pam,cn=auth",
126 pi->svc.bv_val, pi->uid.bv_val, global_host_bv.bv_val);
127 slap_sasl2dn(op, &sdn, &pi->dn, 0);
128 op->o_tmpfree( sdn.bv_val, op->o_tmpmemctx );
131 /* If no luck, do a basic uid search */
132 if (BER_BVISEMPTY(&pi->dn) && (ni->ni_pam_opts & NI_PAM_UID2DN)) {
133 nssov_uid2dn(op, ni, &pi->uid, &pi->dn);
134 if (!BER_BVISEMPTY(&pi->dn)) {
136 dnNormalize( 0, NULL, NULL, &sdn, &pi->dn, op->o_tmpmemctx );
139 if (BER_BVISEMPTY(&pi->dn)) {
140 return NSLCD_PAM_USER_UNKNOWN;
145 int pam_do_bind(nssov_info *ni,TFILE *fp,Operation *op,
149 slap_callback cb = {0};
150 SlapReply rs = {REP_RESULT};
152 pi->msg.bv_val = pi->pwd.bv_val;
154 pi->authz = NSLCD_PAM_SUCCESS;
159 rc = pam_uid2dn(ni, op, pi);
162 if (BER_BVISEMPTY(&pi->pwd)) {
163 rc = NSLCD_PAM_PERM_DENIED;
167 /* Should only need to do this once at open time, but there's always
168 * the possibility that ppolicy will get loaded later.
171 rc = slap_find_control_id(LDAP_CONTROL_PASSWORDPOLICYREQUEST,
174 /* of course, 0 is a valid cid, but it won't be ppolicy... */
176 op->o_ctrlflag[ppolicy_cid] = SLAP_CONTROL_NONCRITICAL;
180 cb.sc_response = pam_bindcb;
182 op->o_callback = &cb;
183 op->o_dn.bv_val[0] = 0;
185 op->o_ndn.bv_val[0] = 0;
186 op->o_ndn.bv_len = 0;
187 op->o_tag = LDAP_REQ_BIND;
188 op->o_protocol = LDAP_VERSION3;
189 op->orb_method = LDAP_AUTH_SIMPLE;
190 op->orb_cred = pi->pwd;
191 op->o_req_dn = pi->dn;
192 op->o_req_ndn = pi->dn;
193 slap_op_time( &op->o_time, &op->o_tincr );
194 rc = op->o_bd->be_bind( op, &rs );
195 memset(pi->pwd.bv_val,0,pi->pwd.bv_len);
196 /* quirk: on successful bind, caller has to send result. we need
197 * to make sure callbacks run.
199 if (rc == LDAP_SUCCESS)
200 send_ldap_result(op, &rs);
202 case LDAP_SUCCESS: rc = NSLCD_PAM_SUCCESS; break;
203 case LDAP_INVALID_CREDENTIALS: rc = NSLCD_PAM_AUTH_ERR; break;
204 default: rc = NSLCD_PAM_AUTH_ERR; break;
207 Debug(LDAP_DEBUG_ANY,"pam_do_bind (%s): rc (%d)\n",
208 pi->dn.bv_val ? pi->dn.bv_val : "NULL", rc, 0);
212 int pam_authc(nssov_info *ni,TFILE *fp,Operation *op,uid_t calleruid)
216 slap_callback cb = {0};
221 struct berval sdn, dn;
225 READ_STRING(fp,uidc);
226 pi.uid.bv_val = uidc;
227 pi.uid.bv_len = tmpint32;
230 pi.dn.bv_len = tmpint32;
231 READ_STRING(fp,svcc);
232 pi.svc.bv_val = svcc;
233 pi.svc.bv_len = tmpint32;
234 READ_STRING(fp,pwdc);
235 pi.pwd.bv_val = pwdc;
236 pi.pwd.bv_len = tmpint32;
238 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authc(%s)\n",
239 pi.uid.bv_val ? pi.uid.bv_val : "NULL",0,0);
243 /* if service is "passwd" and "nssov-pam-password-prohibit-message */
244 /* is set, deny the auth request */
245 if (!strcmp(svcc, "passwd") &&
246 !BER_BVISEMPTY(&ni->ni_pam_password_prohibit_message)) {
247 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authc(): %s (%s)\n",
248 "password_prohibit_message for passwd",
249 ni->ni_pam_password_prohibit_message.bv_val,0);
250 ber_str2bv(ni->ni_pam_password_prohibit_message.bv_val, 0, 0, &pi.msg);
251 pi.authz = NSLCD_PAM_PERM_DENIED;
252 rc = NSLCD_PAM_PERM_DENIED;
256 /* if username is null, pwdmgr password preliminary check */
257 if (BER_BVISEMPTY(&pi.uid)) {
258 if (BER_BVISEMPTY(&ni->ni_pam_pwdmgr_dn)) {
259 /* pwdmgr dn not configured */
260 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authc(prelim check): %s\n",
261 "pwdmgr dn not configured", 0, 0);
262 ber_str2bv("pwdmgr dn not configured", 0, 0, &pi.msg);
263 pi.authz = NSLCD_PAM_PERM_DENIED;
264 rc = NSLCD_PAM_PERM_DENIED;
266 } else if (calleruid != 0) {
267 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authc(prelim check): %s\n",
268 "caller is not root", 0, 0);
269 ber_str2bv("only root may do that", 0, 0, &pi.msg);
270 pi.authz = NSLCD_PAM_PERM_DENIED;
271 rc = NSLCD_PAM_PERM_DENIED;
275 ber_str2bv(ni->ni_pam_pwdmgr_dn.bv_val, 0, 0, &pi.dn);
278 /* use pwdmgr pwd if configured */
279 if (BER_BVISEMPTY(&pi.pwd)) {
280 if (BER_BVISEMPTY(&ni->ni_pam_pwdmgr_pwd)) {
281 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authc(prelim check): %s\n",
282 "no pwdmgr pwd", 0, 0);
283 ber_str2bv("pwdmgr pwd not configured", 0, 0, &pi.msg);
284 pi.authz = NSLCD_PAM_PERM_DENIED;
285 rc = NSLCD_PAM_PERM_DENIED;
288 /* use configured pwdmgr pwd */
289 memset((void *) pwdc, 0, 256);
290 strncpy(pi.pwd.bv_val, ni->ni_pam_pwdmgr_pwd.bv_val,
291 ni->ni_pam_pwdmgr_pwd.bv_len);
292 pi.pwd.bv_len = ni->ni_pam_pwdmgr_pwd.bv_len;
298 rc = pam_do_bind(ni, fp, op, &pi);
301 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authc(%s): rc (%d)\n",
302 pi.dn.bv_val ? pi.dn.bv_val : "NULL",rc,0);
303 WRITE_INT32(fp,NSLCD_VERSION);
304 WRITE_INT32(fp,NSLCD_ACTION_PAM_AUTHC);
305 WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
306 WRITE_BERVAL(fp,&pi.uid);
307 WRITE_BERVAL(fp,&pi.dn);
309 WRITE_INT32(fp,pi.authz); /* authz */
310 WRITE_BERVAL(fp,&pi.msg); /* authzmsg */
314 static struct berval grpmsg =
315 BER_BVC("Access denied by group check");
316 static struct berval hostmsg =
317 BER_BVC("Access denied for this host");
318 static struct berval svcmsg =
319 BER_BVC("Access denied for this service");
320 static struct berval uidmsg =
321 BER_BVC("Access denied by UID check");
323 static int pam_compare_cb(Operation *op, SlapReply *rs)
325 if (rs->sr_err == LDAP_COMPARE_TRUE)
326 op->o_callback->sc_private = (void *)1;
330 int pam_authz(nssov_info *ni,TFILE *fp,Operation *op)
332 struct berval dn, uid, svc, ruser, rhost, tty;
333 struct berval authzmsg = BER_BVNULL;
344 slap_callback cb = {0};
346 READ_STRING(fp,uidc);
348 uid.bv_len = tmpint32;
351 dn.bv_len = tmpint32;
352 READ_STRING(fp,svcc);
354 svc.bv_len = tmpint32;
355 READ_STRING(fp,ruserc);
356 ruser.bv_val = ruserc;
357 ruser.bv_len = tmpint32;
358 READ_STRING(fp,rhostc);
359 rhost.bv_val = rhostc;
360 rhost.bv_len = tmpint32;
361 READ_STRING(fp,ttyc);
363 tty.bv_len = tmpint32;
365 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authz(%s)\n",
366 dn.bv_val ? dn.bv_val : "NULL",0,0);
368 /* If we didn't do authc, we don't have a DN yet */
369 if (BER_BVISEMPTY(&dn)) {
374 rc = pam_uid2dn(ni, op, &pi);
379 /* See if they have access to the host and service */
380 if ((ni->ni_pam_opts & NI_PAM_HOSTSVC) && nssov_pam_svc_ad) {
381 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
382 struct berval hostdn = BER_BVNULL;
383 struct berval odn = op->o_ndn;
384 SlapReply rs = {REP_RESULT};
388 nssov_mapinfo *mi = &ni->ni_maps[NM_host];
390 struct berval filter = {sizeof(fbuf),fbuf};
391 SlapReply rs2 = {REP_RESULT};
393 /* Lookup the host entry */
394 nssov_filter_byname(mi,0,&global_host_bv,&filter);
395 cb.sc_private = &hostdn;
396 cb.sc_response = nssov_name2dn_cb;
397 op->o_callback = &cb;
398 op->o_req_dn = mi->mi_base;
399 op->o_req_ndn = mi->mi_base;
400 op->ors_scope = mi->mi_scope;
401 op->ors_filterstr = filter;
402 op->ors_filter = str2filter_x(op, filter.bv_val);
403 op->ors_attrs = slap_anlist_no_attrs;
404 op->ors_tlimit = SLAP_NO_LIMIT;
406 rc = op->o_bd->be_search(op, &rs2);
407 filter_free_x(op, op->ors_filter, 1);
409 if (BER_BVISEMPTY(&hostdn) &&
410 !BER_BVISEMPTY(&ni->ni_pam_defhost)) {
411 filter.bv_len = sizeof(fbuf);
412 filter.bv_val = fbuf;
413 rs_reinit(&rs2, REP_RESULT);
414 nssov_filter_byname(mi,0,&ni->ni_pam_defhost,&filter);
415 op->ors_filterstr = filter;
416 op->ors_filter = str2filter_x(op, filter.bv_val);
417 rc = op->o_bd->be_search(op, &rs2);
418 filter_free_x(op, op->ors_filter, 1);
421 /* no host entry, no default host -> deny */
422 if (BER_BVISEMPTY(&hostdn)) {
423 rc = NSLCD_PAM_PERM_DENIED;
429 cb.sc_response = pam_compare_cb;
430 cb.sc_private = NULL;
431 op->o_tag = LDAP_REQ_COMPARE;
432 op->o_req_dn = hostdn;
433 op->o_req_ndn = hostdn;
434 ava.aa_desc = nssov_pam_svc_ad;
437 rc = op->o_bd->be_compare( op, &rs );
438 if ( cb.sc_private == NULL ) {
440 rc = NSLCD_PAM_PERM_DENIED;
447 /* See if they're a member of the group */
448 if ((ni->ni_pam_opts & NI_PAM_USERGRP) &&
449 !BER_BVISEMPTY(&ni->ni_pam_group_dn) &&
450 ni->ni_pam_group_ad) {
451 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
452 SlapReply rs = {REP_RESULT};
453 op->o_callback = &cb;
454 cb.sc_response = pam_compare_cb;
455 cb.sc_private = NULL;
456 op->o_tag = LDAP_REQ_COMPARE;
457 op->o_req_dn = ni->ni_pam_group_dn;
458 op->o_req_ndn = ni->ni_pam_group_dn;
459 ava.aa_desc = ni->ni_pam_group_ad;
462 rc = op->o_bd->be_compare( op, &rs );
463 if ( cb.sc_private == NULL ) {
465 rc = NSLCD_PAM_PERM_DENIED;
470 /* We need to check the user's entry for these bits */
471 if ((ni->ni_pam_opts & (NI_PAM_USERHOST|NI_PAM_USERSVC)) ||
472 ni->ni_pam_template_ad ||
473 ni->ni_pam_min_uid || ni->ni_pam_max_uid ) {
474 rc = be_entry_get_rw( op, &dn, NULL, NULL, 0, &e );
475 if (rc != LDAP_SUCCESS) {
476 rc = NSLCD_PAM_USER_UNKNOWN;
480 if ((ni->ni_pam_opts & NI_PAM_USERHOST) && nssov_pam_host_ad) {
481 a = attr_find(e->e_attrs, nssov_pam_host_ad);
482 if (!a || attr_valfind( a,
483 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
484 SLAP_MR_VALUE_OF_SYNTAX,
485 &global_host_bv, NULL, op->o_tmpmemctx )) {
486 rc = NSLCD_PAM_PERM_DENIED;
491 if ((ni->ni_pam_opts & NI_PAM_USERSVC) && nssov_pam_svc_ad) {
492 a = attr_find(e->e_attrs, nssov_pam_svc_ad);
493 if (!a || attr_valfind( a,
494 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
495 SLAP_MR_VALUE_OF_SYNTAX,
496 &svc, NULL, op->o_tmpmemctx )) {
497 rc = NSLCD_PAM_PERM_DENIED;
506 if (ni->ni_pam_min_uid || ni->ni_pam_max_uid) {
509 nssov_mapinfo *mi = &ni->ni_maps[NM_passwd];
510 a = attr_find(e->e_attrs, mi->mi_attrs[UIDN_KEY].an_desc);
512 rc = NSLCD_PAM_PERM_DENIED;
516 id = (int)strtol(a->a_vals[0].bv_val,&tmp,0);
517 if (a->a_vals[0].bv_val[0] == '\0' || *tmp != '\0') {
518 rc = NSLCD_PAM_PERM_DENIED;
522 if ((ni->ni_pam_min_uid && id < ni->ni_pam_min_uid) ||
523 (ni->ni_pam_max_uid && id > ni->ni_pam_max_uid)) {
524 rc = NSLCD_PAM_PERM_DENIED;
530 if (ni->ni_pam_template_ad) {
531 a = attr_find(e->e_attrs, ni->ni_pam_template_ad);
534 else if (!BER_BVISEMPTY(&ni->ni_pam_template))
535 uid = ni->ni_pam_template;
537 rc = NSLCD_PAM_SUCCESS;
540 WRITE_INT32(fp,NSLCD_VERSION);
541 WRITE_INT32(fp,NSLCD_ACTION_PAM_AUTHZ);
542 WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
543 WRITE_BERVAL(fp,&uid);
544 WRITE_BERVAL(fp,&dn);
546 WRITE_BERVAL(fp,&authzmsg);
548 be_entry_release_r(op, e);
551 case NSLCD_PAM_SUCCESS:
552 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authz(): success\n", 0,0,0);
554 case NSLCD_PAM_PERM_DENIED:
555 Debug(LDAP_DEBUG_TRACE,"nssov_pam_authz(): %s\n",
556 authzmsg.bv_val ? authzmsg.bv_val : "NULL",0,0);
559 Debug(LDAP_DEBUG_TRACE,
560 "nssov_pam_authz(): permission denied, rc (%d)\n",
566 static int pam_sess(nssov_info *ni,TFILE *fp,Operation *op,int action)
568 struct berval dn, uid, svc, tty, rhost, ruser;
576 slap_callback cb = {0};
577 SlapReply rs = {REP_RESULT};
578 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
579 struct berval timestamp, bv[2], *nbv;
585 READ_STRING(fp,uidc);
587 uid.bv_len = tmpint32;
590 dn.bv_len = tmpint32;
591 READ_STRING(fp,svcc);
593 svc.bv_len = tmpint32;
594 READ_STRING(fp,ttyc);
596 tty.bv_len = tmpint32;
597 READ_STRING(fp,rhostc);
598 rhost.bv_val = rhostc;
599 rhost.bv_len = tmpint32;
600 READ_STRING(fp,ruserc);
601 ruser.bv_val = ruserc;
602 ruser.bv_len = tmpint32;
603 READ_INT32(fp,stamp);
605 Debug(LDAP_DEBUG_TRACE,"nssov_pam_sess_%c(%s)\n",
606 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c', dn.bv_val,0);
609 Debug(LDAP_DEBUG_TRACE,"nssov_pam_sess_%c(): %s\n",
610 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c', "null DN",0);
615 if (!ni->ni_pam_sessions) {
616 Debug(LDAP_DEBUG_TRACE,"nssov_pam_sess_%c(): %s\n",
617 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c',
618 "pam session(s) not configured, ignored",0);
625 for (i=0; !BER_BVISNULL(&ni->ni_pam_sessions[i]); i++) {
626 if (ni->ni_pam_sessions[i].bv_len != svc.bv_len)
628 if (!strcasecmp(ni->ni_pam_sessions[i].bv_val, svc.bv_val)) {
634 Debug(LDAP_DEBUG_TRACE,
635 "nssov_pam_sess_%c(): service(%s) not configured, ignored\n",
636 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c',
643 slap_op_time( &op->o_time, &op->o_tincr );
644 timestamp.bv_len = sizeof(timebuf);
645 timestamp.bv_val = timebuf;
646 if (action == NSLCD_ACTION_PAM_SESS_O )
648 slap_timestamp( &stamp, ×tamp );
649 bv[0].bv_len = timestamp.bv_len + global_host_bv.bv_len + svc.bv_len +
650 tty.bv_len + ruser.bv_len + rhost.bv_len + STRLENOF(" (@)");
651 bv[0].bv_val = op->o_tmpalloc( bv[0].bv_len+1, op->o_tmpmemctx );
652 sprintf(bv[0].bv_val, "%s %s %s %s (%s@%s)",
653 timestamp.bv_val, global_host_bv.bv_val, svc.bv_val, tty.bv_val,
654 ruser.bv_val, rhost.bv_val);
656 Debug(LDAP_DEBUG_TRACE, "nssov_pam_sess_%c(): loginStatus (%s) \n",
657 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c', bv[0].bv_val,0);
662 attr_normalize( ad_loginStatus, bv, &nbv, op->o_tmpmemctx );
663 mod.sml_nvalues = nbv;
664 mod.sml_desc = ad_loginStatus;
665 mod.sml_op = action == NSLCD_ACTION_PAM_SESS_O ? LDAP_MOD_ADD :
667 mod.sml_flags = SLAP_MOD_INTERNAL;
670 cb.sc_response = slap_null_cb;
671 op->o_callback = &cb;
672 op->o_tag = LDAP_REQ_MODIFY;
673 op->o_dn = op->o_bd->be_rootdn;
674 op->o_ndn = op->o_bd->be_rootndn;
675 op->orm_modlist = &mod;
676 op->orm_no_opattrs = 1;
679 if (op->o_bd->be_modify( op, &rs ) != LDAP_SUCCESS) {
680 Debug(LDAP_DEBUG_TRACE,
681 "nssov_pam_sess_%c(): modify op failed\n",
682 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c',
687 if ( mod.sml_next ) {
688 slap_mods_free( mod.sml_next, 1 );
690 ber_bvarray_free_x( nbv, op->o_tmpmemctx );
695 Debug(LDAP_DEBUG_TRACE,
696 "nssov_pam_sess_%c(): success\n",
697 action==NSLCD_ACTION_PAM_SESS_O ? 'o' : 'c',
699 sessionID = op->o_time;
701 WRITE_INT32(fp,NSLCD_VERSION);
702 WRITE_INT32(fp,action);
703 WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
704 WRITE_INT32(fp,sessionID);
708 int pam_sess_o(nssov_info *ni,TFILE *fp,Operation *op)
710 return pam_sess(ni,fp,op,NSLCD_ACTION_PAM_SESS_O);
713 int pam_sess_c(nssov_info *ni,TFILE *fp,Operation *op)
715 return pam_sess(ni,fp,op,NSLCD_ACTION_PAM_SESS_C);
718 int pam_pwmod(nssov_info *ni,TFILE *fp,Operation *op,uid_t calleruid)
730 READ_STRING(fp,uidc);
731 pi.uid.bv_val = uidc;
732 pi.uid.bv_len = tmpint32;
735 pi.dn.bv_len = tmpint32;
736 READ_STRING(fp,svcc);
737 pi.svc.bv_val = svcc;
738 pi.svc.bv_len = tmpint32;
739 READ_STRING(fp,opwc);
740 pi.pwd.bv_val = opwc;
741 pi.pwd.bv_len = tmpint32;
742 READ_STRING(fp,npwc);
744 npw.bv_len = tmpint32;
746 Debug(LDAP_DEBUG_TRACE,"nssov_pam_pwmod(%s), %s\n",
747 pi.dn.bv_val ? pi.dn.bv_val : "NULL",
748 pi.uid.bv_val ? pi.uid.bv_val : "NULL" ,0);
753 /* nssov_pam prohibits password mod */
754 if (!BER_BVISEMPTY(&ni->ni_pam_password_prohibit_message)) {
755 Debug(LDAP_DEBUG_TRACE,"nssov_pam_pwmod(): %s (%s)\n",
756 "password_prohibit_message",
757 ni->ni_pam_password_prohibit_message.bv_val,0);
758 ber_str2bv(ni->ni_pam_password_prohibit_message.bv_val, 0, 0, &pi.msg);
759 rc = NSLCD_PAM_PERM_DENIED;
763 if (BER_BVISEMPTY(&pi.dn)) {
764 /* should not be here at all, pam_authc() should have returned */
766 Debug(LDAP_DEBUG_TRACE,"nssov_pam_pwmod(), %s\n",
767 "prelim checking failed", 0, 0);
768 ber_str2bv("no pwmod requesting dn", 0, 0, &pi.msg);
769 rc = NSLCD_PAM_PERM_DENIED;
773 if (!BER_BVISEMPTY(&ni->ni_pam_pwdmgr_dn) &&
774 !ber_bvcmp(&pi.dn, &ni->ni_pam_pwdmgr_dn)) {
775 if (calleruid != 0) {
776 Debug(LDAP_DEBUG_TRACE,"nssov_pam_pwmod(): %s\n",
777 "caller is not root", 0, 0);
778 ber_str2bv("only root may do that", 0, 0, &pi.msg);
779 rc = NSLCD_PAM_PERM_DENIED;
782 /* root user requesting pwmod, convert uid to dn */
784 rc = pam_uid2dn(ni, op, &pi);
786 ber_str2bv("unable to convert uid to dn", 0, 0, &pi.msg);
787 rc = NSLCD_PAM_PERM_DENIED;
792 if (!pi.ispwdmgr && BER_BVISEMPTY(&pi.pwd)) {
793 Debug(LDAP_DEBUG_TRACE,"nssov_pam_pwmod(), %s\n",
794 "not pwdmgr and old pwd empty", 0, 0);
795 ber_str2bv("must provide old password", 0, 0, &pi.msg);
796 rc = NSLCD_PAM_PERM_DENIED;
800 BerElementBuffer berbuf;
801 BerElement *ber = (BerElement *)&berbuf;
803 SlapReply rs = {REP_RESULT};
804 slap_callback cb = {0};
806 ber_init_w_nullc(ber, LBER_USE_DER);
807 ber_printf(ber, "{");
808 if (!BER_BVISEMPTY(&pi.dn))
809 ber_printf(ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID,
811 /* supply old pwd whenever it's given */
812 if (!BER_BVISEMPTY(&pi.pwd))
813 ber_printf(ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD,
815 if (!BER_BVISEMPTY(&npw))
816 ber_printf(ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW,
818 ber_printf(ber, "N}");
819 ber_flatten2(ber, &bv, 0);
820 op->o_tag = LDAP_REQ_EXTENDED;
821 op->ore_reqoid = slap_EXOP_MODIFY_PASSWD;
822 op->ore_reqdata = &bv;
825 /* root user changing end-user passwords */
826 op->o_dn = ni->ni_pam_pwdmgr_dn;
827 op->o_ndn = ni->ni_pam_pwdmgr_dn;
829 /* end-user self-pwd-mod */
833 op->o_callback = &cb;
834 op->o_conn->c_authz_backend = op->o_bd;
835 cb.sc_response = slap_null_cb;
836 op->o_bd = frontendDB;
837 rc = op->o_bd->be_extended(op, &rs);
839 ber_str2bv(rs.sr_text, 0, 0, &pi.msg);
840 if (rc == LDAP_SUCCESS)
841 rc = NSLCD_PAM_SUCCESS;
843 rc = NSLCD_PAM_PERM_DENIED;
846 Debug(LDAP_DEBUG_TRACE,"nssov_pam_pwmod(), rc (%d)\n", rc, 0, 0);
847 WRITE_INT32(fp,NSLCD_VERSION);
848 WRITE_INT32(fp,NSLCD_ACTION_PAM_PWMOD);
849 WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
850 WRITE_BERVAL(fp,&pi.uid);
851 WRITE_BERVAL(fp,&pi.dn);
853 WRITE_BERVAL(fp,&pi.msg);
862 code = slap_str2ad("loginStatus", &ad_loginStatus, &text);