circle-3.1/bin/
circle-3.1/cnf/
circle-3.1/lib/
circle-3.1/lib/etc/
circle-3.1/lib/house/
circle-3.1/lib/misc/
circle-3.1/lib/plralias/A-E/
circle-3.1/lib/plralias/F-J/
circle-3.1/lib/plralias/K-O/
circle-3.1/lib/plralias/P-T/
circle-3.1/lib/plralias/U-Z/
circle-3.1/lib/plralias/ZZZ/
circle-3.1/lib/plrobjs/
circle-3.1/lib/plrobjs/A-E/
circle-3.1/lib/plrobjs/F-J/
circle-3.1/lib/plrobjs/K-O/
circle-3.1/lib/plrobjs/P-T/
circle-3.1/lib/plrobjs/U-Z/
circle-3.1/lib/plrobjs/ZZZ/
circle-3.1/lib/text/
circle-3.1/lib/text/help/
circle-3.1/lib/world/
circle-3.1/lib/world/shp/
circle-3.1/log/
circle-3.1/src/doc/
/* ************************************************************************
*  file:  mudpasswd.c                                 Part of CircleMud   *
*  Usage: changing passwords of chars in a Diku playerifle                *
*  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
*  All Rights Reserved                                                    *
************************************************************************* */


#include "conf.h"
#include "sysdep.h"

#include "structs.h"
#include "utils.h"


int str_eq(char *s, char *t)
{
  for (;;) {
    if (*s == 0 && *t == 0)
      return (TRUE);
    if (LOWER(*s) != LOWER(*t))
      return (FALSE);
    s++;
    t++;
  }
}


void pword(char *filename, char *name, char *password)
{
  FILE *fl;
  struct char_file_u buf;
  int found = FALSE;
  long size;

  if (!(fl = fopen(filename, "r+"))) {
    perror(filename);
    exit(1);
  }
  fseek(fl, 0L, SEEK_END);
  size = ftell(fl);
  rewind(fl);
  if (size % sizeof(struct char_file_u)) {
    fprintf(stderr, "\aWARNING:  File size does not match structure, recompile mudpasswd.\n");
    fclose(fl);
    exit(1);
  }

  for (;;) {
    fread(&buf, sizeof(buf), 1, fl);
    if (feof(fl))
      break;

    if (str_eq(name, buf.name)) {
      found = TRUE;
      strncpy(buf.pwd, CRYPT(password, buf.name), MAX_PWD_LENGTH);
      if (fseek(fl, -1L * sizeof(buf), SEEK_CUR) != 0)
	perror("fseek");
      if (fwrite(&buf, sizeof(buf), 1, fl) != 1)
	perror("fwrite");
      if (fseek(fl, 0L, SEEK_CUR) != 0)
	perror("fseek");
    }
  }

  if (found) {
    printf("%s password is now %s\n", name, password);
  } else {
    printf("%s not found\n", name);
  }

  fclose(fl);
}


int main(int argc, char **argv)
{
  if (argc != 4)
    fprintf(stderr, "Usage: %s playerfile character-name new-password\n", argv[0]);
  else
    pword(argv[1], argv[2], argv[3]);

  return (0);
}