lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1060 - in nss-pam-ldapd: . nslcd

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd commit: r1060 - in nss-pam-ldapd: . nslcd



Author: arthur
Date: Sun Jan 24 18:07:11 2010
New Revision: 1060
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1060

Log:
add --with-bindpw-file configure option to enable reading the bindpw option 
from a file

Modified:
   nss-pam-ldapd/configure.ac
   nss-pam-ldapd/nslcd/cfg.c

Modified: nss-pam-ldapd/configure.ac
==============================================================================
--- nss-pam-ldapd/configure.ac  Sun Jan 24 15:33:21 2010        (r1059)
+++ nss-pam-ldapd/configure.ac  Sun Jan 24 18:07:11 2010        (r1060)
@@ -2,7 +2,7 @@
 #
 # Copyright (C) 2006 Luke Howard
 # Copyright (C) 2006 West Consulting
-# Copyright (C) 2006, 2007, 2008, 2009 Arthur de Jong
+# Copyright (C) 2006, 2007, 2008, 2009, 2010 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -169,6 +169,15 @@
 AC_DEFINE_UNQUOTED(NSLCD_CONF_PATH,"$NSLCD_CONF_PATH",[Path to nslcd 
configuration file.])
 AC_SUBST(NSLCD_CONF_PATH)
 
+# check the name of the file with a bindpw value
+AC_ARG_WITH(bindpw-file,
+            AS_HELP_STRING([--with-bindpw-file=PATH],
+                           [path to file with value for bindpw 
@<:@disabled@:>@]),
+            [ NSLCD_BINDPW_PATH="$with_bindpw_file"
+              AC_DEFINE_UNQUOTED(NSLCD_BINDPW_PATH,"$NSLCD_BINDPW_PATH",[Path 
to bindpw value.])
+              AC_SUBST(NSLCD_BINDPW_PATH)
+            ])
+
 # where should the pidfile be written
 AC_ARG_WITH(nslcd-pidfile,
             AS_HELP_STRING([--with-nslcd-pidfile=PATH],

Modified: nss-pam-ldapd/nslcd/cfg.c
==============================================================================
--- nss-pam-ldapd/nslcd/cfg.c   Sun Jan 24 15:33:21 2010        (r1059)
+++ nss-pam-ldapd/nslcd/cfg.c   Sun Jan 24 18:07:11 2010        (r1060)
@@ -699,7 +699,7 @@
     exit(EXIT_FAILURE);
   }
   /* read file and parse lines */
-  while (fgets(linebuf,MAX_LINE_LENGTH,fp)!=NULL)
+  while (fgets(linebuf,sizeof(linebuf),fp)!=NULL)
   {
     lnr++;
     line=linebuf;
@@ -984,6 +984,59 @@
   fclose(fp);
 }
 
+#ifdef NSLCD_BINDPW_PATH
+static void bindpw_read(const char *filename,struct ldap_config *cfg)
+{
+  FILE *fp;
+  char linebuf[MAX_LINE_LENGTH];
+  int i;
+  /* open config file */
+  errno=0;
+  if ((fp=fopen(filename,"r"))==NULL)
+  {
+    if (errno==ENOENT)
+    {
+      log_log(LOG_DEBUG,"no bindpw file (%s)",filename);
+      return; /* ignore */
+    }
+    else
+    {
+      log_log(LOG_ERR,"cannot open bindpw file (%s): 
%s",filename,strerror(errno));
+      exit(EXIT_FAILURE);
+    }
+  }
+  /* read the first line */
+  if (fgets(linebuf,sizeof(linebuf),fp)==NULL)
+  {
+    log_log(LOG_ERR,"%s: error reading first line",filename);
+    exit(EXIT_FAILURE);
+  }
+  /* chop the last char off and save the rest as bindpw */
+  i=strlen(linebuf);
+
+  i=(int)strlen(linebuf);
+  if ((i<=0)||(linebuf[i-1]!='\n'))
+  {
+    log_log(LOG_ERR,"%s:1: line too long or missing newline",filename);
+    exit(EXIT_FAILURE);
+  }
+  linebuf[i-1]='\0';
+  if (strlen(linebuf)==0)
+  {
+    log_log(LOG_ERR,"%s:1: the password is empty",filename);
+    exit(EXIT_FAILURE);
+  }
+  cfg->ldc_bindpw=strdup(linebuf);
+  /* check if there is no more data in the file */
+  if (fgets(linebuf,sizeof(linebuf),fp)!=NULL)
+  {
+    log_log(LOG_ERR,"%s:2: there is more than one line in the bindpw 
file",filename);
+    exit(EXIT_FAILURE);
+  }
+  fclose(fp);
+}
+#endif /* NSLCD_BINDPW_PATH */
+
 /* This function tries to get the LDAP search base from the LDAP server.
    Note that this returns a string that has been allocated with strdup().
    For this to work the myldap module needs enough configuration information
@@ -1055,6 +1108,9 @@
   cfg_defaults(nslcd_cfg);
   /* read configfile */
   cfg_read(fname,nslcd_cfg);
+#ifdef NSLCD_BINDPW_PATH
+  bindpw_read(NSLCD_BINDPW_PATH,nslcd_cfg);
+#endif /* NSLCD_BINDPW_PATH */
   /* do some sanity checks */
   if (nslcd_cfg->ldc_uris[0].uri==NULL)
   {
--
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits