File: preauthshadow.c

package info (click to toggle)
courier-authlib 0.69.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,340 kB
  • sloc: ansic: 15,551; sh: 4,627; cpp: 4,172; makefile: 774; perl: 747
file content (74 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
** Copyright 1998 - 2005 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#if	HAVE_CONFIG_H
#include	"courier_auth_config.h"
#endif
#include	<time.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<errno.h>
#include	<pwd.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#if	HAVE_SHADOW_H
#include	<shadow.h>
#endif


#include	"auth.h"
#include	"courierauthdebug.h"


int auth_shadow_pre(const char *userid, const char *service,
	int (*callback)(struct authinfo *, void *),
			void *arg)
{
struct authinfo auth;
struct passwd *pw;
struct spwd *spw;
long today;

	memset(&auth, 0, sizeof(auth));

	if ((pw=getpwnam(userid)) == NULL)
	{
		if (errno == ENOMEM)	return 1;
		return -1;
	}

	if ((spw=getspnam(userid)) == NULL)
	{
		if (errno == ENOMEM)	return 1;
		return -1;
	}

	today = (long)time(NULL)/(24L*60*60);

	if ((spw->sp_expire > 0) && (today > spw->sp_expire))
	{
		DPRINTF("authshadow: %s - account expired", userid);
		return -1;			/* account expired */
	}

	if ((spw->sp_lstchg != -1) && (spw->sp_max != -1) &&
		((spw->sp_lstchg + spw->sp_max) < today))
	{
		DPRINTF("authshadow: %s - password expired", userid);
		return -1;			/* password expired */
	}

	auth.sysusername=userid;
	auth.sysgroupid=pw->pw_gid;
	auth.homedir=pw->pw_dir;
	auth.address=userid;
	auth.fullname=pw->pw_gecos;
	auth.passwd=spw->sp_pwdp;

	courier_authdebug_authinfo("DEBUG: authshadow: ", &auth, 0, pw->pw_passwd);
	return ((*callback)(&auth, arg));
}