tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* getpwnam
@ 1997-06-06 19:35 Ellen Davis
  0 siblings, 0 replies; only message in thread
From: Ellen Davis @ 1997-06-06 19:35 UTC (permalink / raw)
  To: tru64-unix-managers


Hi,

I am not sure if this is an appropriate posting , but I need help with a C
program.  I've received help here before so I thought I'd give it a try.
IF there is a more appropriate group, pardon my post and please let me know.

I am running DU 4.0B on a AlphaServer 1000A.  I have a program which reads
a dbm file and then does a getpwnam call.  Before the getpwnam call, the
data from the dbm file is fine and can be printed.  After the call, the
data is lost.  A printf prints null strings!  What happened to my data?

My program:

#include <stdio.h>
#include <ndbm.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <time.h>
#include <pwd.h>
#include <string.h>

char *EmployeeDBM = "employee";

/* employeedbm record */
#define EMPLOYEEDBM_RECORD_SIZE   111
#define SIZE_EMPLOYEEDBM_FNAME     14
#define SIZE_EMPLOYEEDBM_MINIT      1
#define SIZE_EMPLOYEEDBM_LNAME     15
#define SIZE_EMPLOYEEDBM_ML         4
#define SIZE_EMPLOYEEDBM_PHONE     10
#define SIZE_EMPLOYEEDBM_STATUS     1
#define SIZE_EMPLOYEEDBM_DEPT      30
#define SIZE_EMPLOYEEDBM_COLLEGE    3
#define SIZE_EMPLOYEEDBM_TITLE     25
#define SIZE_EMPLOYEEDBM_BMONTH     2
#define SIZE_EMPLOYEEDBM_BDAY       2

struct employeedbm_record
{
  char  fname[14],
        minit[1],
        lname[15],
        ml[4],
        phone[10],
        status[1],
        dept[30],
        college[3],
        title[25],
        bmonth[2],
        bday[2],
        filler[2],
        stopper;
};


main() {

struct employeedbm_record *EmployeeDBMRecord;

struct passwd *pwptr;
char *lower_uid = "daviser";
char *ssnumber = "xxxxxxxxx";
int i;
char social[9];
datum key;
datum content;
DBM *dbm;

strcpy(social,"xxxxxxxxx");
dbm = dbm_open(EmployeeDBM, O_RDONLY , S_IRUSR | S_IWUSR);
if (dbm == NULL){
  printf("Cannot open employee dbm file\n");
  exit(1);
}
key.dptr = social;
key.dsize = 10;
content = dbm_fetch(dbm,key);
dbm_close(dbm);
if (content.dptr == NULL) {
        return(0);
}
else {
  EmployeeDBMRecord = (struct employeedbm_record *) content.dptr;

  }
printf("before %s\n",(EmployeeDBMRecord));  /* works */

pwptr = getpwnam(lower_uid);

printf("after %s\n",(EmployeeDBMRecord));  /* does not work - prints nulls */

printf("username %s\n",pwptr->pw_name);  /* prints name correctly */
}


 Ellen Davis

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-06-06 19:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-06-06 19:35 getpwnam Ellen Davis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox