1 \ 2\0/*)
\0 * getpwnam(name) - retrieves a UAF entry
\0\ 2\0 *
\1c\0 * Author: Patrick L. Mahan
\15\0 * Location: TGV, Inc
\0\15\0 * Date: 15-Nov-1991
\0\ 2\0 *>
\0 * Purpose: Provides emulation for the UNIX getpwname routine.
\ 2\0 *
\17\0 * Modification History
\0\ 2\0 *'
\0 * Date | Who | Version | Reason
\0G
\0 * ------------+-----------+---------------+---------------------------
\0)
\0 * 15-Nov-1991 | PLM | 1.0 | First Write
\0\ 3\0 */
\0\0\0\16\0#define PASSWDROUTINES
\0\0\12\0#include <stdio.h>
\14\0#include <descrip.h>
\13\0#include <uaidef.h>
\0\10\0#include "pwd.h"
\0\0\f\0struct uic {
\16\0 unsigned short uid;
\16\0 unsigned short gid;
\ 2\0};
\0\0-
\0#define TEST(ptr, str) { if (ptr == NULL) { \
\0I
\0 fprintf(stderr, "getpwnam: memory allocation failure for \"%s\"\n", \
\0\f\0 str); \'
\0 return ((struct passwd *)(NULL)); \
\0\b\0 } }
\0\0\1d\0struct passwd *getpwnam(name)
\0\v\0char *name;
\0\ 1\0{
\0\10\0 int istatus;
\14\0 int UserNameLen;
\15\0 int UserOwnerLen;
\0\16\0 int UserDeviceLen;
\13\0 int UserDirLen;
\0\15\0 char UserName[13];
\0\16\0 char UserOwner[32];
\17\0 char UserDevice[32];
\0\14\0 char UserDir[64];
\15\0 char *cptr, *sptr;
\0 \0 unsigned long int UserPwd[2];
\1f\0 unsigned short int UserSalt;
\0!
\0 unsigned long int UserEncrypt;
\0\17\0 struct uic UicValue;
\0\18\0 struct passwd *entry;
\0\0%
\0 struct dsc$descriptor_s VMSNAME =
\04
\0 {strlen(name), DSC$K_DTYPE_T, DSC$K_CLASS_S, name};
\0\0\14\0 struct itmlist3 {
\e\0 unsigned short int length;
\0\19\0 unsigned short int item;
\0\19\0 unsigned long int addr;
\0\1c\0 unsigned long int retaddr;
\13\0 } ItemList[] = {
\01
\0 {12, UAI$_USERNAME, &UserName, &UserNameLen},
\0\1d\0 {8, UAI$_PWD, &UserPwd, 0},
\0\1e\0 {4, UAI$_UIC, &UicValue, 0},-
\0 {32, UAI$_OWNER, &UserOwner, &UserOwnerLen},
\00
\0 {32, UAI$_DEFDEV, &UserDevice, &UserDeviceLen},*
\0 {64, UAI$_DEFDIR, &UserDir, &UserDirLen},
\1f\0 {2, UAI$_SALT, &UserSalt, 0},
\0%
\0 {4, UAI$_ENCRYPT, &UserEncrypt, 0},
\0\r\0 {0, 0, 0, 0}
\0\ 5\0 };
\0\0\0\13\0 UserNameLen = 0;
\0=
\0 istatus = sys$getuai (0, 0, &VMSNAME, &ItemList, 0, 0, 0);
\0\0\0\18\0 if (!(istatus & 1)) {
\f\0#ifdef DEBUG
\15\0 lib$signal(istatus);
\0\12\0#endif /* DEBUG */G
\0 fprintf (stderr, "getpwnam: unable to retrieve passwd entry for %s\n",
\0\17\0 name);
\0C
\0 fprintf (stderr, "getpwnam: vms error number is 0x%x\n", istatus);
\0 \0 return ((struct passwd *)NULL);
\ 4\0 }
\0\0?
\0 entry = (struct passwd *) calloc (1, sizeof(struct passwd));
\0\1f\0 TEST(entry, "PASSWD_ENTRY");
\0\0\0 \0 entry->pw_uid = UicValue.uid;
\0 entry->pw_gid = UicValue.gid;
\1d\0 entry->pw_salt = UserSalt;
\0#
\0 entry->pw_encrypt = UserEncrypt;
\0\0\0\13\0 sptr = UserName;
\0/
\0 cptr = calloc (UserNameLen+1, sizeof(char));
\0\1a\0 TEST(cptr, "USERNAME");%
\0 strncpy (cptr, sptr, UserNameLen);
\0\1c\0 cptr[UserNameLen] = '\0';
\19\0 entry->pw_name = cptr;
\0\0\0"
\0 cptr = calloc(8, sizeof(char));
\1a\0 TEST(cptr, "PASSWORD");
\1c\0 memcpy(cptr, UserPwd, 8);
\e\0 entry->pw_passwd = cptr;
\0\0\0\1c\0 sptr = UserOwner; sptr++;5
\0 cptr = calloc ((int)UserOwner[0]+1, sizeof(char));
\0\1a\0 TEST(cptr, "FULLNAME");+
\0 strncpy (cptr, sptr, (int)UserOwner[0]);
\0"
\0 cptr[(int)UserOwner[0]] = '\0';
\1a\0 entry->pw_gecos = cptr;
\0\0F
\0 cptr = calloc ((int)UserDevice[0]+(int)UserDir[0]+1, sizeof(char));
\16\0 TEST(cptr, "HOME");
\1d\0 sptr = UserDevice; sptr++;
\0,
\0 strncpy (cptr, sptr, (int)UserDevice[0]);
\1a\0 sptr = UserDir; sptr++;)
\0 strncat (cptr, sptr, (int)UserDir[0]);
\03
\0 cptr[(int)UserDevice[0]+(int)UserDir[0]] = '\0';
\0\18\0 entry->pw_dir = cptr;
\0\0E
\0 cptr = calloc (strlen("SYS$SYSTEM:LOGINOUT.EXE")+1, sizeof(char));
\0\16\0 TEST(cptr,"SHELL");,
\0 strcpy (cptr, "SYS$SYSTEM:LOGINOUT.EXE");
\1a\0 entry->pw_shell = cptr;
\0\0\12\0 return (entry);
\ 1\0}
\0