2 ** Copyright 1998 - 2005 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
24 #include "courierauthdebug.h"
26 static const char rcsid
[]="$Id: preauthshadow.c,v 1.9 2005/11/17 01:29:03 mrsam Exp $";
28 int auth_shadow_pre(const char *userid
, const char *service
,
29 int (*callback
)(struct authinfo
*, void *),
37 memset(&auth
, 0, sizeof(auth
));
39 if ((pw
=getpwnam(userid
)) == NULL
)
41 if (errno
== ENOMEM
) return 1;
45 if ((spw
=getspnam(userid
)) == NULL
)
47 if (errno
== ENOMEM
) return 1;
51 today
= (long)time(NULL
)/(24L*60*60);
53 if ((spw
->sp_expire
> 0) && (today
> spw
->sp_expire
))
55 DPRINTF("authshadow: %s - account expired", userid
);
56 return -1; /* account expired */
59 if ((spw
->sp_lstchg
!= -1) && (spw
->sp_max
!= -1) &&
60 ((spw
->sp_lstchg
+ spw
->sp_max
) < today
))
62 DPRINTF("authshadow: %s - password expired", userid
);
63 return -1; /* password expired */
66 auth
.sysusername
=userid
;
67 auth
.sysgroupid
=pw
->pw_gid
;
68 auth
.homedir
=pw
->pw_dir
;
70 auth
.fullname
=pw
->pw_gecos
;
71 auth
.passwd
=spw
->sp_pwdp
;
73 courier_authdebug_authinfo("DEBUG: authshadow: ", &auth
, 0, pw
->pw_passwd
);
74 return ((*callback
)(&auth
, arg
));