summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-11-29 00:05:49 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-11-29 00:05:49 -0500
commit7b3f020c821c79e21a2b0b2216a7ad6073e15bee (patch)
treea79b20b97597e6f89b773fceea04e0df483986c4
parent75c8aca8a994f95a106ffde78c5645b946fb99a1 (diff)
wip db_shadow
-rw-r--r--nslcd.h2
-rw-r--r--nslcd/db_shadow.c80
2 files changed, 40 insertions, 42 deletions
diff --git a/nslcd.h b/nslcd.h
index c9857d6..9083cc1 100644
--- a/nslcd.h
+++ b/nslcd.h
@@ -195,6 +195,8 @@
INT32 inact
INT32 expire
INT32 flag */
+/* It is my understanding that an empty value for those INT32 fields
+ is expressed with a negative number. -- lukeshu */
#define NSLCD_ACTION_SHADOW_BYNAME 0x000c0001
#define NSLCD_ACTION_SHADOW_ALL 0x000c0008
diff --git a/nslcd/db_shadow.c b/nslcd/db_shadow.c
index 7e24ea4..081738b 100644
--- a/nslcd/db_shadow.c
+++ b/nslcd/db_shadow.c
@@ -36,6 +36,19 @@
#include "cfg.h"
#include "attmap.h"
+struct shadow {
+ /* for the integers: a value < 0 means empty */
+ char *name; /* the account name */
+ char *hash; /* a crypt(3) formatted password hash */
+ int32_t lastchange_date; /* days since Jan 1, 1970 */
+ int32_t min_days; /* minimum number of days between changes */
+ int32_t max_days; /* maximum number of days between changes */
+ int32_t warn_days; /* how long before max_days is up to warn the user */
+ int32_t inact_days; /* how long after max_days to accept the pw */
+ int32_t expire_date; /* days since Jarn 1, 1970 */
+ int32_t flag; /* unused on Linux/Glibc */
+};
+
static long to_date(const char *dn, const char *date, const char *attr)
{
char buffer[32];
@@ -140,52 +153,35 @@ void get_shadow_properties(MYLDAP_ENTRY *entry, long *lastchangedate,
}
}
-static int write_shadow(TFILE *fp, MYLDAP_ENTRY *entry, const char *requser,
- uid_t calleruid)
+static int write_shadow(TFILE *fp, struct shadow *entry, uid_t calleruid)
{
int32_t tmpint32;
- const char **usernames;
- const char *passwd;
- long lastchangedate;
- long mindays;
- long maxdays;
- long warndays;
- long inactdays;
- long expiredate;
- unsigned long flag;
- int i;
- char passbuffer[BUFLEN_PASSWORDHASH];
- /* get username */
- usernames = myldap_get_values(entry, attmap_shadow_uid);
- if ((usernames == NULL) || (usernames[0] == NULL))
+ struct shadow _entry = {
+ .name = pentry->pw_name;
+ .hash = pentry->pw_passwd;
+ .lastchange_date = -1;
+ .min_days = -1;
+ .max_days = -1;
+ .warn_days = -1;
+ .inact_days = -1;
+ .expire_date = -1;
+ .flag = -1;
+ };
+ struct shadow *entry = &_entry;
+
+ if (caller_uid == 0)
{
- log_log(LOG_WARNING, "%s: %s: missing",
- myldap_get_dn(entry), attmap_shadow_uid);
- return 0;
+ WRITE_INT32(fp, NSLCD_RESULT_BEGIN);
+ WRITE_STRING(fp, entry->name);
+ WRITE_STRING(fp, entry->hash ? entry->hash : "!");
+ WRITE_INT32( fp, entry->lastchange_date);
+ WRITE_INT32( fp, entry->min_days);
+ WRITE_INT32( fp, entry->max_days);
+ WRITE_INT32( fp, entry->warn_days);
+ WRITE_INT32( fp, entry->inact_days);
+ WRITE_INT32( fp, entry->expire_date);
+ WRITE_INT32( fp, entry->flag);
}
- /* get password */
- passwd = get_userpassword(entry, attmap_shadow_userPassword,
- passbuffer, sizeof(passbuffer));
- if ((passwd == NULL) || (calleruid != 0))
- passwd = default_shadow_userPassword;
- /* get expiry properties */
- get_shadow_properties(entry, &lastchangedate, &mindays, &maxdays, &warndays,
- &inactdays, &expiredate, &flag);
- /* write the entries */
- for (i = 0; usernames[i] != NULL; i++)
- if ((requser == NULL) || (STR_CMP(requser, usernames[i]) == 0))
- {
- WRITE_INT32(fp, NSLCD_RESULT_BEGIN);
- WRITE_STRING(fp, usernames[i]);
- WRITE_STRING(fp, passwd);
- WRITE_INT32(fp, lastchangedate);
- WRITE_INT32(fp, mindays);
- WRITE_INT32(fp, maxdays);
- WRITE_INT32(fp, warndays);
- WRITE_INT32(fp, inactdays);
- WRITE_INT32(fp, expiredate);
- WRITE_INT32(fp, flag);
- }
return 0;
}