I've been using the crypt() command to verify users, against a passwd file
in my programs,   However, now that i Upgraded to RedHat 5.0
this Command Now Just Spits Out Errors(on compilation)!   I have to put it
back on the old machine to compile,
then move the binary back...  (PAIN.)  old machine was RedHat 4.0 & 3.0 (both
work)

reading the MAN-PAGES,  i added this, (only difference i could find.)
#define _XOPEN_SOURCE

and i keep getting this new compiler error:
/tmp/cca038241.o: In function `CheckPassword':
/tmp/cca038241.o(.text+0x18f): undefined reference to `crypt'

if anyone could share some wisdom,  it would be appreciated!! (Source Below)
-Joe


-----PASSWORD.H SOURCE----------
#define _XOPEN_SOURCE
int CheckPassword(char *Name, char *Pass);
//  Returns (1) if Password Is Correct, (0) Otherwise.
//  Uses 'passwd' file in current Directory.
---------------------------------------------

----------------------PASSWORD.C SOURCE-------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "password.h"

int CheckPassword(char *Username,char *Pass) {
  FILE *F;
  int r1=0,DONE=0,PASSCORRECT=0;
  char Salt[100];
  char *RealCryp;
  char Cryp[20];
  char ch=0;
  F=fopen("./passwd","rb");
  while ((DONE==0)&&(!feof(F))) {
    fread(&ch,1,1,F);
    if (ch=='\n') {
      r1=0;
      fread(&ch,1,1,F);
      while ((ch==Username[r1])&&(DONE==0)) {
        ++r1;
        fread(&ch,1,1,F);
        if ((Username[r1]==0)&&(ch==':')) {
           DONE=1; ch=0;
        };
      };
    };
  };

  if (DONE==1) {
    PASSCORRECT=1;
    fread(&ch,1,1,F);
    for (r1=0;r1<=12;++r1) {      ///  13 characters to a passwd
       Cryp[r1]=ch;
       fread(&ch,1,1,F);
    }
    Cryp[13]=0;
    Salt[0]=Cryp[0];
    Salt[1]=Cryp[1];
    Salt[2]=0;
    RealCryp=crypt(Pass,Salt);
    for (r1=0; r1<=12;++r1) if (RealCryp[r1]!=Cryp[r1])  PASSCORRECT=0;
  }
  fclose(F);
  return PASSCORRECT;
}

----------------------------------------------------------------------------

Reply via email to