//Sample code file: var/ndk/webBuildengine/tmp/viewable_samples/a4ad0b48-dd95-46b6-8289-721e99c8dc76/login_method/lcm/linux/src/cpwdlcm.c

//Warning: This code has been marked up for HTML

// cpwdlcm.cpp : Defines the entry point for the DLL application.
//
class='cKeyword'>#include<stdio.h>
class='cKeyword'>#include <ntypes.h>
class='cKeyword'>#include <nmasmaf.h>

typedef struct CPWD_INFO
{
   nuint32 error;      // non-zero are failures
   nuint32 infoFlags;   // information flags
} CPWD_INFO;

class='cKeyword'>char      pwd[128];

//*******************************************************************
//
//   Entry point that NMAS will load
//
//*******************************************************************

int LCM00000001( MAF_Handle mh ) {
   nint32      err = 0, mafErr =0;
   CPWD_INFO   pwdInfo;
   size_t      replyLen = 0;
   FILE *stream = NULL;
printf("In LSMCPWD LCM\n");   
   // start NMAS
   mafErr = MAF_Begin (mh);
   
printf("MAF_Begin return %d\n", mafErr);


   if (mafErr)
   {   
      // very bad error if this fails just error out
      return mafErr;
   }
   
   memset(pwd, 0xCC, sizeof(pwd));
   // check that the password is not too big for static buffer
   
   stream = popen("/opt/novell/nmas/methods/clrpwd/cpwdgui", "r");   
   fgets(pwd, 128, stream);
   pclose(stream);   

//   strcpy(pwd, "dude");
   
   // set password information
   pwdInfo.error = 0;
   pwdInfo.infoFlags = 0;

   // send password information
   mafErr = MAF_Write(mh, sizeof(pwdInfo), &pwdInfo);
   if (mafErr)
   {
      goto MAF_ERROR;
   }

   // send password over MAF encrypted transport
   mafErr = MAF_XWrite(mh, strlen(pwd), pwd); // Do not include null
   if (mafErr)
   {
      goto MAF_ERROR;
   }

   mafErr = MAF_Read(mh, &replyLen, &err);
   if (mafErr || replyLen < 4 || err)
   {
      goto MAF_ERROR;
   }

   if (err)
   {
      MAF_Write(mh, 4, &err);
   }

MAF_ERROR:

   if (!err)
   {
      err = mafErr;
   }

   // close the session
   MAF_End (mh, err, 0, 0);

   // return only fatal MAF errors
   return mafErr;
}