nss-pam-ldapd commit: r1840 - nss-pam-ldapd/nslcd
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
nss-pam-ldapd commit: r1840 - nss-pam-ldapd/nslcd
- From: Commits of the nss-pam-ldapd project <nss-pam-ldapd-commits [at] lists.arthurdejong.org>
- To: nss-pam-ldapd-commits [at] lists.arthurdejong.org
- Reply-to: nss-pam-ldapd-users [at] lists.arthurdejong.org
- Subject: nss-pam-ldapd commit: r1840 - nss-pam-ldapd/nslcd
- Date: Sun, 25 Nov 2012 16:51:11 +0100 (CET)
Author: arthur
Date: Sun Nov 25 16:51:10 2012
New Revision: 1840
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?revision=1840&view=revision
Log:
move all nsswitch-parsing related functions to nsswitch.c
Modified:
nss-pam-ldapd/nslcd/common.h
nss-pam-ldapd/nslcd/nsswitch.c
nss-pam-ldapd/nslcd/passwd.c
Modified: nss-pam-ldapd/nslcd/common.h
==============================================================================
--- nss-pam-ldapd/nslcd/common.h Sun Nov 25 16:44:17 2012 (r1839)
+++ nss-pam-ldapd/nslcd/common.h Sun Nov 25 16:51:10 2012 (r1840)
@@ -127,8 +127,11 @@
long *inactdays,long *expiredate,unsigned long
*flag);
+/* check whether the nsswitch file should be reloaded */
+void nsswitch_check_reload(void);
+
/* check whether the nsswitch.conf file has LDAP as a naming source for db */
-int nsswitch_db_uses_ldap(const char *filename,const char *db);
+int nsswitch_shadow_uses_ldap(void);
/* fallback definition of HOST_NAME_MAX */
#ifndef HOST_NAME_MAX
Modified: nss-pam-ldapd/nslcd/nsswitch.c
==============================================================================
--- nss-pam-ldapd/nslcd/nsswitch.c Sun Nov 25 16:44:17 2012 (r1839)
+++ nss-pam-ldapd/nslcd/nsswitch.c Sun Nov 25 16:51:10 2012 (r1840)
@@ -25,16 +25,49 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
#include "common.h"
#include "log.h"
+/* the cached value of whether shadow lookups use LDAP in nsswitch.conf */
+#define NSSWITCH_FILE "/etc/nsswitch.conf"
+#define CACHED_UNKNOWN 22
+static int cached_shadow_uses_ldap=CACHED_UNKNOWN;
+static time_t cached_shadow_lastcheck=0;
+#define CACHED_SHADOW_TIMEOUT (60)
+static time_t nsswitch_mtime=0;
+
/* the maximum line length supported of nsswitch.conf */
#define MAX_LINE_LENGTH 4096
-
-/* TODO: store mtime of file and use it to check reparse */
-/* TODO: cache entries for x minutes */
+/* check whether /etc/nsswitch.conf should be related to update
+ cached_shadow_uses_ldap */
+void nsswitch_check_reload(void)
+{
+ struct stat buf;
+ time_t t;
+ if ((cached_shadow_uses_ldap!=CACHED_UNKNOWN)&&
+ ((t=time(NULL)) > (cached_shadow_lastcheck+CACHED_SHADOW_TIMEOUT)))
+ {
+ cached_shadow_lastcheck=t;
+ if (stat(NSSWITCH_FILE,&buf))
+ {
+ log_log(LOG_ERR,"stat(%s) failed: %s",NSSWITCH_FILE,strerror(errno));
+ /* trigger a recheck anyway */
+ cached_shadow_uses_ldap=CACHED_UNKNOWN;
+ return;
+ }
+ /* trigger a recheck if file changed */
+ if (buf.st_mtime!=nsswitch_mtime)
+ {
+ nsswitch_mtime=buf.st_mtime;
+ cached_shadow_uses_ldap=CACHED_UNKNOWN;
+ }
+ }
+}
/* see if the line is a service definition for db and return a pointer to
the beginning of the services list if it is */
@@ -89,24 +122,24 @@
return 0;
}
-int nsswitch_db_uses_ldap(const char *filename,const char *db)
+static int shadow_uses_ldap(void)
{
FILE *fp;
int lnr=0;
char linebuf[MAX_LINE_LENGTH];
const char *services;
/* open config file */
- if ((fp=fopen(filename,"r"))==NULL)
+ if ((fp=fopen(NSSWITCH_FILE,"r"))==NULL)
{
- log_log(LOG_ERR,"cannot open %s: %s",filename,strerror(errno));
+ log_log(LOG_ERR,"cannot open %s: %s",NSSWITCH_FILE,strerror(errno));
return 0;
}
/* read file and parse lines */
while (fgets(linebuf,sizeof(linebuf),fp)!=NULL)
{
lnr++;
- services=find_db(linebuf,db);
- if ((services!=NULL)&&has_service(services,"ldap",filename,lnr))
+ services=find_db(linebuf,"shadow");
+ if ((services!=NULL)&&has_service(services,"ldap",NSSWITCH_FILE,lnr))
{
fclose(fp);
return 1;
@@ -115,3 +148,15 @@
fclose(fp);
return 0;
}
+
+/* check whether shadow lookups are configured to use ldap */
+inline int nsswitch_shadow_uses_ldap(void)
+{
+ if (cached_shadow_uses_ldap==CACHED_UNKNOWN)
+ {
+ log_log(LOG_INFO,"(re)loading %s",NSSWITCH_FILE);
+ cached_shadow_uses_ldap=shadow_uses_ldap();
+ cached_shadow_lastcheck=time(NULL);
+ }
+ return cached_shadow_uses_ldap;
+}
Modified: nss-pam-ldapd/nslcd/passwd.c
==============================================================================
--- nss-pam-ldapd/nslcd/passwd.c Sun Nov 25 16:44:17 2012 (r1839)
+++ nss-pam-ldapd/nslcd/passwd.c Sun Nov 25 16:51:10 2012 (r1840)
@@ -28,7 +28,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
@@ -386,59 +385,9 @@
}
#ifndef NSS_FLAVOUR_GLIBC
-
/* only check nsswitch.conf for glibc */
#define check_nsswitch_reload()
#define shadow_uses_ldap() (1)
-
-#else /* NSS_FLAVOUR_GLIBC */
-
-/* the cached value of whether shadow lookups use LDAP in nsswitch.conf */
-#define NSSWITCH_FILE "/etc/nsswitch.conf"
-#define CACHED_UNKNOWN 22
-static int cached_shadow_uses_ldap=CACHED_UNKNOWN;
-static time_t cached_shadow_lastcheck=0;
-#define CACHED_SHADOW_TIMEOUT (60)
-static time_t nsswitch_mtime=0;
-
-/* check whether /etc/nsswitch.conf should be related to update
- cached_shadow_uses_ldap */
-static inline void check_nsswitch_reload(void)
-{
- struct stat buf;
- time_t t;
- if ((cached_shadow_uses_ldap!=CACHED_UNKNOWN)&&
- ((t=time(NULL)) > (cached_shadow_lastcheck+CACHED_SHADOW_TIMEOUT)))
- {
- cached_shadow_lastcheck=t;
- if (stat(NSSWITCH_FILE,&buf))
- {
- log_log(LOG_ERR,"stat(%s) failed: %s",NSSWITCH_FILE,strerror(errno));
- /* trigger a recheck anyway */
- cached_shadow_uses_ldap=CACHED_UNKNOWN;
- return;
- }
- /* trigger a recheck if file changed */
- if (buf.st_mtime!=nsswitch_mtime)
- {
- nsswitch_mtime=buf.st_mtime;
- cached_shadow_uses_ldap=CACHED_UNKNOWN;
- }
- }
-}
-
-/* check whether shadow lookups are configured to use ldap */
-static inline int shadow_uses_ldap(void)
-{
- if (cached_shadow_uses_ldap==CACHED_UNKNOWN)
- {
- log_log(LOG_INFO,"(re)loading %s",NSSWITCH_FILE);
- cached_shadow_uses_ldap=nsswitch_db_uses_ldap(NSSWITCH_FILE,"shadow");
- cached_shadow_lastcheck=time(NULL);
- }
- return cached_shadow_uses_ldap;
-}
-
#endif /* NSS_FLAVOUR_GLIBC */
/* the maximum number of uidNumber attributes per entry */
@@ -471,7 +420,7 @@
}
/* if we are using shadow maps and this entry looks like it would return
shadow information, make the passwd entry indicate it */
- if (myldap_has_objectclass(entry,"shadowAccount")&&shadow_uses_ldap())
+ if
(myldap_has_objectclass(entry,"shadowAccount")&&nsswitch_shadow_uses_ldap())
{
passwd="x";
}
@@ -604,7 +553,7 @@
log_log(LOG_WARNING,"request denied by validnames option");
return -1;
}
- check_nsswitch_reload();,
+ nsswitch_check_reload();,
NSLCD_ACTION_PASSWD_BYNAME,
mkfilter_passwd_byname(name,filter,sizeof(filter)),
write_passwd(fp,entry,name,NULL,calleruid)
@@ -623,7 +572,7 @@
WRITE_INT32(fp,NSLCD_ACTION_PASSWD_BYUID);
WRITE_INT32(fp,NSLCD_RESULT_END);
}
- check_nsswitch_reload();,
+ nsswitch_check_reload();,
NSLCD_ACTION_PASSWD_BYUID,
mkfilter_passwd_byuid(uid,filter,sizeof(filter)),
write_passwd(fp,entry,NULL,&uid,calleruid)
@@ -633,7 +582,7 @@
passwd,all,
const char *filter;
log_setrequest("passwd(all)");
- check_nsswitch_reload();,
+ nsswitch_check_reload();,
NSLCD_ACTION_PASSWD_ALL,
(filter=passwd_filter,0),
write_passwd(fp,entry,NULL,NULL,calleruid)
--
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits/
- nss-pam-ldapd commit: r1840 - nss-pam-ldapd/nslcd,
Commits of the nss-pam-ldapd project