Re: How to change the unix passwd from 4gl /SPL
Posted in 1996
This is the C source I use on SCO Unix OpenServer 5 : static char *version = "mod_passwd 01.01"; /***************************************************************************** mod_passwd.c Modify password. *****************************************************************************/ /* * Usage : * * Change the passwd without checking the old one (for administrators) * - mod_passwd userid newpasswd * * Change the passwd with checking the old one (for users) * - mod_passwd userid oldpasswd newpasswd */ /** Include files **/ #include <sys/types.h> #include <sys/security.h> #include <sys/audit.h> #include <prot.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <time.h> /** Global variables **/ static struct pr_passwd *p; /***************************************************************************** Main control routine *****************************************************************************/ int main(argc, argv) int argc; char *argv[]; { char salt[3], *passwd, *newpasswd; /* * If you don't call set_auth_parameters you get the error : * "set_auth_parameters(S) has not been called, see identity(S)" */ set_auth_parameters(argc, argv); /* * Check the parameters */ if ((argc < 3) && (argc > 4)) { return (1); } /* * Get info about the user */ if ((p = getprpwnam(argv[1])) == NULL) { return (1); } /* * Check if old password is also passed */ if (argc == 4) { salt[0] = p->ufld.fd_encrypt[0]; salt[1] = p->ufld.fd_encrypt[1]; salt[2] = '\\0'; if (strcmp(bigcrypt(argv[2], salt), p->ufld.fd_encrypt) != 0 ) return(2); } /* * Encrypt the passwd. */ sprintf(salt,"%2.2d",(time((time_t *)NULL) % 100)); strcpy(p->ufld.fd_encrypt, bigcrypt(argv[argc - 1], salt)); return (putprpwnam(argv[1], p) ? 0 : 1); } /** EOF **/ The only thing you have to do is write a SP that issues a "system" command and traps "ISAM" errors 1,2 and 3. Some calls in the C source are SCO specific, but I think you can find the same type of calls on other Unix flavors. Koen