Sponsored Content
Operating Systems AIX How to check password expiry in AIX? Post 302273407 by aixylinux on Sunday 4th of January 2009 01:29:29 PM
Old 01-04-2009
Use passwdexpired system call

If you can write a C program, you can call the passwdexpired() system call to get this information. See:

Help -

Here's a code fragment that does the trick. Unfortunately, due to employer restrictions, I can't share the whole code with you. I hacked this out of an existing module, so it is illustrative only.

/* typical includes needed by C programs */
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

/* this is the include needed for passwdexpired */
#include <usersec.h>

void main( int argc, char* argv[]) {
char* userid=argv[1];

char p[100] = "";
int rc;

rc = putenv( "LANG=C" ); /* force LANG=C */

/* get password date expiration string */
rc = passwdexpired( userid, &p );
if ( rc == 1 || rc == 2 )
{
printf( "%s\nReset the password \n", p);
exit( 2 );
}

/* some other error */
if ( rc != 0 )
{
if ( errno == ENOENT || errno == ESRCH )
{
fprintf( stderr, "User %s is not defined\n", userid );
}
else
{
fprintf( stderr, "passwdexpired() rc=%d, %s\n", rc, strerror(errno) );
}
exit( 1 );
}

printf( "passwdexpired returned message:\n'%s'\n", p );

}

The binary file must be setuid root, else root must run the program.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

password expiry

Hi, under SUN Unix, in which file the expiry date of a user password is indicated ? Many thanks. (2 Replies)
Discussion started by: big123456
2 Replies

2. Solaris

Notification of password expiry.

Hi, Is there any way of sending an email to a number of users indicating that the passwords of user accounts will expire? Currently we have a test server with a number of oracle test accounts on it. Each of these accounts correspond to an instance of Oracle on the server. These... (2 Replies)
Discussion started by: sparcman
2 Replies

3. Solaris

Notification of password expiry.

Hi, Is there any way of sending an email to a number of users indicating that the passwords of user accounts will expire? Currently we have a test server with a number of oracle test accounts on it. Each of these accounts correspond to an instance of Oracle on the server. These... (2 Replies)
Discussion started by: sparcman
2 Replies

4. Solaris

SSH Password-less login fails on password expiry.

Hi Gurus I have a few Sol 5.9 servers and i have enabled password less authentication between them for my user ID. Often i have found that when my password has expired,the login fails. Resetting my password reenables the keys. Do i need to do something to avoid this scenario or is this... (2 Replies)
Discussion started by: Renjesh
2 Replies

5. Shell Programming and Scripting

password expiry notification

Hi, Could someone please let me know how to write script for passwd expiry notification on salaries boxes. Regards Dnyan (1 Reply)
Discussion started by: dnyan
1 Replies

6. Solaris

disable password expiry

Hi How do i disable password expiration on ldap? It runs on Solaris 10 machine. Thanks in advance. (3 Replies)
Discussion started by: hrist
3 Replies

7. Shell Programming and Scripting

Password expiry date check for hp servers

Hi All, Can anybody help me, to find the command to check for the password expiry date for the hp servers. Thanks, Deepak (3 Replies)
Discussion started by: dswain
3 Replies

8. Shell Programming and Scripting

Password expiry report

Hi All, I want to write a script that will send the alert when linux server password expiry for user 'x' is less than 12 days. I have written the below script but this is not working for expiry date 04 july script;- P_EXPIRY_DATE=`chage -l msdp| grep 'Password expires' | awk ' {... (2 Replies)
Discussion started by: abhigrkist
2 Replies

9. Solaris

Command to find out password expiry

Hi, I would like to know is there command which will tell me when password will be expire and when last password was changed ? like on linux chage -l <username? (2 Replies)
Discussion started by: manoj.solaris
2 Replies

10. AIX

UNIX cmd to check for non expiry type password

Hi, Here's the version of unix that we are working on. > uname -a AIX yyyyyyyy 1 6 00F613E24C00 @:on(cluster303)/iishomea/kmani00-> i have application id: aaabbb Now i need to check whether the password for the application id set to non expiry type or not. Moreover, with that unix... (3 Replies)
Discussion started by: kmanivan82
3 Replies
GETGROUPLIST(3) 					     Linux Programmer's Manual						   GETGROUPLIST(3)

NAME
getgrouplist - get list of groups to which a user belongs SYNOPSIS
#include <grp.h> int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): getgrouplist(): _BSD_SOURCE DESCRIPTION
The getgrouplist() function scans the group database (see group(5)) to obtain the list of groups that user belongs to. Up to *ngroups of these groups are returned in the array groups. If it was not among the groups defined for user in the group database, then group is included in the list of groups returned by getgrou- plist(); typically this argument is specified as the group ID from the password record for user. The ngroups argument is a value-result argument: on return it always contains the number of groups found for user, including group; this value may be greater than the number of groups stored in groups. RETURN VALUE
If the number of groups of which user is a member is less than or equal to *ngroups, then the value *ngroups is returned. If the user is a member of more than *ngroups groups, then getgrouplist() returns -1. In this case the value returned in *ngroups can be used to resize the buffer passed to a further call getgrouplist(). VERSIONS
This function is present since glibc 2.2.4. CONFORMING TO
This function is nonstandard; it appears on most BSDs. BUGS
In glibc versions before 2.3.3, the implementation of this function contains a buffer-overrun bug: it returns the complete list of groups for user in the array groups, even when the number of groups exceeds *ngroups. EXAMPLE
The program below displays the group list for the user named in its first command-line argument. The second command-line argument speci- fies the ngroups value to be supplied to getgrouplist(). The following shell session shows examples of the use of this program: $ ./a.out cecilia 0 getgrouplist() returned -1; ngroups = 3 $ ./a.out cecilia 3 ngroups = 3 16 (dialout) 33 (video) 100 (users) Program source #include <stdio.h> #include <stdlib.h> #include <grp.h> #include <pwd.h> int main(int argc, char *argv[]) { int j, ngroups; gid_t *groups; struct passwd *pw; struct group *gr; if (argc != 3) { fprintf(stderr, "Usage: %s <user> <ngroups> ", argv[0]); exit(EXIT_FAILURE); } ngroups = atoi(argv[2]); groups = malloc(ngroups * sizeof (gid_t)); if (groups == NULL) { perror("malloc"); exit(EXIT_FAILURE); } /* Fetch passwd structure (contains first group ID for user) */ pw = getpwnam(argv[1]); if (pw == NULL) { perror("getpwnam"); exit(EXIT_SUCCESS); } /* Retrieve group list */ if (getgrouplist(argv[1], pw->pw_gid, groups, &ngroups) == -1) { fprintf(stderr, "getgrouplist() returned -1; ngroups = %d ", ngroups); exit(EXIT_FAILURE); } /* Display list of retrieved groups, along with group names */ fprintf(stderr, "ngroups = %d ", ngroups); for (j = 0; j < ngroups; j++) { printf("%d", groups[j]); gr = getgrgid(groups[j]); if (gr != NULL) printf(" (%s)", gr->gr_name); printf(" "); } exit(EXIT_SUCCESS); } SEE ALSO
getgroups(2), setgroups(2), getgrent(3), group(5), passwd(5) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2008-07-03 GETGROUPLIST(3)
All times are GMT -4. The time now is 12:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy