~ubuntu-branches/ubuntu/utopic/nss-pam-ldapd/utopic

« back to all changes in this revision

Viewing changes to pam/pam.c

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2013-05-05 20:00:00 UTC
  • mfrom: (16.1.6) (14.1.6 experimental)
  • Revision ID: package-import@ubuntu.com-20130505200000-nhg39y204kr141mz
Tags: 0.8.13-1
* New upstream release
  - include an extra sanity check to ensure not too many file
    descriptors are open
  - fix handling of gid configuration option if it listed before the uid
    option
  - return NSS_STATUS_TRYAGAIN on zero-length (but not-NULL) buffer (thanks
    Jakub Hrozek)
  - provide an _nss_ldap_version symbol in the NSS module to help debug
    problems with a newer nslcd
  - retry updating the lastChange attribute with the normal nslcd LDAP
    connection if the update with the user's connection failed
  - avoid processing passwd_byuid requests for uids below nss_min_uid
  - fix a few minor or very unlikely to occur memory leaks
  - miscellaneous minor changes, fixes and compatibility improvements
* drop 01-fix-set-usec-instead-of-sec.patch which is part of 0.8.13
* remove compatibility code that converted nss-ldapd.conf to nslcd.conf
  for upgrading from pre-0.7 versions of nss-ldapd (thanks Dominik George)
* remove code for fixing permissions when upgrading from a pre-0.6.7.1
  version
* updated Turkish debconf translation by Atila KOÇ (closes: #701067)
* drop Richard A Nelson from uploaders
* add build dependency on autotools-dev to ensure config.sub and
  config.guess are automatically updated during build

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
   pam.c - pam module functions
3
3
 
4
4
   Copyright (C) 2009 Howard Chu
5
 
   Copyright (C) 2009, 2010, 2011, 2012 Arthur de Jong
 
5
   Copyright (C) 2009, 2010, 2011, 2012, 2013 Arthur de Jong
6
6
 
7
7
   This library is free software; you can redistribute it and/or
8
8
   modify it under the terms of the GNU Lesser General Public
363
363
    READ_BUF_STRING(fp,ctx->authzmsg);)
364
364
}
365
365
 
 
366
static int nslcd_request_config_get(pam_handle_t *pamh,struct pld_ctx *ctx,struct pld_cfg *cfg,
 
367
                               int cfgopt,char **value)
 
368
{
 
369
  PAM_REQUEST(NSLCD_ACTION_CONFIG_GET,
 
370
    /* log debug message */
 
371
    pam_syslog(pamh,LOG_DEBUG,"nslcd request config (%d)",cfgopt),
 
372
    /* write the request parameter */
 
373
    WRITE_INT32(fp,cfgopt),
 
374
    /* read the result entry */
 
375
    READ_BUF_STRING(fp,*value);)
 
376
}
 
377
 
366
378
/* remap the return code based on the configuration */
367
379
static int remap_pam_rc(int rc,struct pld_cfg *cfg)
368
380
{
380
392
  struct pld_cfg cfg;
381
393
  struct pld_ctx *ctx;
382
394
  const char *username,*service;
 
395
  char *prohibit_message;
383
396
  char *passwd=NULL;
384
397
  /* set up configuration */
385
398
  cfg_init(pamh,flags,argc,argv,&cfg);
386
399
  rc=init(pamh,&cfg,&ctx,&username,&service);
387
400
  if (rc!=PAM_SUCCESS)
388
401
    return remap_pam_rc(rc,&cfg);
 
402
  /* if service is "passwd" and pwdmod is not allowed alert user */
 
403
  if (!strcmp(service,"passwd"))
 
404
  {
 
405
    rc=nslcd_request_config_get(pamh,ctx,&cfg,NSLCD_CONFIG_PAM_PASSWORD_PROHIBIT_MESSAGE,&prohibit_message);
 
406
    if ((rc==PAM_SUCCESS)&&(prohibit_message!=NULL)&&(prohibit_message[0]!='\0'))
 
407
    {
 
408
      /* we silently ignore errors to get the configuration option */
 
409
      pam_syslog(pamh,LOG_NOTICE,"password change prohibited: %s; user=%s",prohibit_message,username);
 
410
      if (!cfg.no_warn)
 
411
        pam_error(pamh,"%s",prohibit_message);
 
412
      return remap_pam_rc(PAM_PERM_DENIED,&cfg);
 
413
    }
 
414
  }
389
415
  /* get the password */
390
416
  rc=pam_get_authtok(pamh,PAM_AUTHTOK,(const char **)&passwd,NULL);
391
417
  if (rc!=PAM_SUCCESS)
467
493
  {
468
494
    /* turn in to generic PAM error message if message is empty */
469
495
    if ((ctx2.authzmsg==NULL)||(ctx2.authzmsg[0]=='\0'))
 
496
    {
470
497
      ctx2.authzmsg=(char *)pam_strerror(pamh,ctx2.authz);
471
 
    pam_syslog(pamh,LOG_NOTICE,"%s; user=%s",ctx2.authzmsg,username);
 
498
      pam_syslog(pamh,LOG_NOTICE,"%s; user=%s",ctx2.authzmsg,username);
 
499
    }
 
500
    else
 
501
      pam_syslog(pamh,LOG_NOTICE,"%s; user=%s; err=%s",ctx2.authzmsg,username,pam_strerror(pamh,rc));
472
502
    rc=remap_pam_rc(ctx2.authz,&cfg);
473
503
    if ((rc!=PAM_IGNORE)&&(!cfg.no_warn))
474
504
      pam_error(pamh,"%s",ctx2.authzmsg);
550
580
  struct pld_ctx *ctx;
551
581
  const char *username,*service;
552
582
  const char *oldpassword=NULL,*newpassword=NULL;
 
583
  char *prohibit_message;
553
584
  struct passwd *pwent;
554
585
  uid_t myuid;
555
586
  /* set up configuration */
557
588
  rc=init(pamh,&cfg,&ctx,&username,&service);
558
589
  if (rc!=PAM_SUCCESS)
559
590
    return remap_pam_rc(rc,&cfg);
 
591
  /* check if password modification is allowed */
 
592
  rc=nslcd_request_config_get(pamh,ctx,&cfg,NSLCD_CONFIG_PAM_PASSWORD_PROHIBIT_MESSAGE,&prohibit_message);
 
593
  if ((rc==PAM_SUCCESS)&&(prohibit_message!=NULL)&&(prohibit_message[0]!='\0'))
 
594
  {
 
595
    /* we silently ignore errors to get the configuration option */
 
596
    pam_syslog(pamh,LOG_NOTICE,"password change prohibited: %s; user=%s",prohibit_message,username);
 
597
    if (!cfg.no_warn)
 
598
      pam_error(pamh,"%s",prohibit_message);
 
599
    return remap_pam_rc(PAM_PERM_DENIED,&cfg);
 
600
  }
560
601
  /* see if we are dealing with an LDAP user first */
561
602
  if (ctx->dn==NULL)
562
603
  {
569
610
  if (flags&PAM_PRELIM_CHECK)
570
611
  {
571
612
    /* see if the user is trying to modify another user's password */
572
 
    pwent=getpwnam(username);
 
613
    pwent=pam_modutil_getpwnam(args->pamh,username);
573
614
    myuid=getuid();
574
615
    if ((pwent!=NULL)&&(pwent->pw_uid!=myuid)&&(!(flags&PAM_CHANGE_EXPIRED_AUTHTOK)))
575
616
    {
614
655
      pam_syslog(pamh,LOG_NOTICE,"%s; user=%s",pam_strerror(pamh,ctx->authok),username);
615
656
    else if (cfg.debug)
616
657
      pam_syslog(pamh,LOG_DEBUG,"authentication succeeded");
617
 
    /* store password (needed if oldpassword was retreived from context) */
 
658
    /* store password (needed if oldpassword was retrieved from context) */
618
659
    if (ctx->authok==PAM_SUCCESS)
619
660
    {
620
661
      rc=pam_set_item(pamh,PAM_OLDAUTHTOK,oldpassword);