Hello!,  I'm getting confused over pointers here,
I am trying to convert a passwd file,  which has TEXT passwords instead
of the
encrypted versions ,  this is suppossed to replace those.
(but i run into pointer problems with the "crypt" command...)
where should my *'s and &'s be?!   (I will use a random SALT once it
works...)
any help would be appreciated!

//  Passwd  TEXT to CRYPT format converter
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define _XOPEN_SOURCE
#include <unistd.h>

void main() {
  FILE *F,*FF;
  char salt[2]="ab";
  char oldpasswd[20], *newpasswd;
  char c;
  int r1;
  F=fopen("./passwd","r");
  FF=fopen("./passwd.new","w");
  while (feof(F)==0) {
    while ((c!=':')&&(feof(F)==0)) { c=fgetc(F); fprintf(FF,"%c",c); }
//Read the [username:]
    r1=-1; c=0;
    while ((c!=':')&&(feof(F)==0)) { c=fgetc(F); ++r1; oldpasswd[r1]=c;
} oldpasswd[r1]=0;
    newpasswd=crypt(oldpasswd,salt);
    if (feof(F)==0) fprintf(FF,"%s:",newpasswd);
    while ((c!='\n')&&(feof(F)==0)) { c=fgetc(F); fprintf(FF,"%c",c); }
//Read the rest
  }
  fclose(FF);
  fclose(F);
}


Reply via email to