#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "custom.h"
#include "global.h"

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_super_util.h"
#include "manhat-lib/shared_authenticate.h"
#include "manhat-lib/shared_cookie.h"
#include "manhat-lib/shared_cs_util.h"


void
delete_super_user_key(const char *key)
{
 char key_path[MAX_PATH + 1];
 char real_keyname[MAX_KEY + 1];
 
 if(SUPER_COOKIES_ENABLED)         /* custom.h */
    check_key_for_cookie(key,real_keyname);     /* shared_util.c */
 else
    strncpy(real_keyname, key, MAX_KEY + 1);
       
 snprintf(key_path, MAX_PATH +1, "../%s/%s/%s/%s",USERS_DIR, ADMIN_DIR,KEY_DIR, real_keyname);       
 unlink(key_path);
}




int
main()
{
   char key[MAX_KEY +1];
   SESSION user;

   cs_cgi_init();
   read_param( key);
   
   validate_super_key(key, &user);
   delete_super_user_key(key);
   
   if(SUPER_COOKIES_ENABLED)
   {
       set_cookie(COOKIE_DONE, SBIN_ALIAS,ALIAS);
            printf("<html><head><meta http-equiv=\"REFRESH\" content=\"1; URL=%s\"></head></html>",  "super_doorstep");
   }
   else
      printf("Location:%s\n\n", "super_doorstep");
   cs_cgi_destroy();
   return 0;
}
