#include <stdio.h>

#include "global.h"

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_cs_util.h"


static void
read_parameters(char *crs, char *key, int *depass)
{
 
 char scratch[20];


 cs_get_optional_parameter ("crs", crs, MAX_PATH);   /* shared_cs_util.c */
 cs_get_required_parameter ("id", key, MAX_KEY);     /* shared_cs_util.c */
   
 /* just check to see if there's a 'depass' parameter */
  cs_get_optional_parameter ("depass", scratch, 19);     /* shared_cs_util.c */
  if(*scratch)
     *depass = 1;
  else
     *depass = 0;

}




int
main (void)
{
  char course[MAX_PATH + 1];	/* from crs=? command line */
  char key[MAX_KEY + 1];	/* from id=? command line */
  SESSION user;
  CONFIG_STRUCT conf;		/* the configuration read from config file */
  int depass;                   /* from optional depass=? cmd line */

  cs_cgi_init();                /* shared_cs_util.c */

  read_parameters(course, key, &depass);
    
  if(*course)
   {
     read_configuration_file (course, &conf);	/* shared_util.c */
     validate_key (key, &user, &conf);          /* shared_util.c */
   }
  else
     validate_server_key(key,&user);  /* shared_util.c */ 

  cs_set_value("realname", user.realname);       /* shared_cs_util.c */
  cs_set_value("username", user.username);       /* shared_cs_util.c */

  if(*course)
      cs_set_course_info(&conf);    /* shared_cs_util.c */
      
  cs_set_current_time();           /* shared_cs_util.c */

  if(depass)
     cs_set_int_value("depass_warn", 1);     /* shared_cs_util.c */
     
  cs_set_int_value("max_pass", MAX_PASSWORD);  /* shared_cs_util.c */


  cs_cgi_display("passwd_form", 1);   /* shared_cs_util.c */
  cs_cgi_destroy();                   /* shared_cs_util.c */
  return 0;
}

