#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/wait.h>
#include<string.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<pthread.h>

#include"zither.h"
#include<almemsys/almemsys.h>
#include"jpreturn.h"


extern global_data_t gd;



//--------------- ALUP_LOGIC 1.1.7 以上-------------------
int aupl_logi(private_data_t * pd)
{
int stat, interval;
stat = 0;
interval = (pd->life.life_int + pd->life.life_los + 15);

int ustat = self_memcmp(pd->rec.user, pd->rec.def_user); 
int astat = self_memcmp(pd->rec.user, "administrator");
int cgstat = self_memcmp(pd->rec.user, "cgiuser");

if(ustat == 0 && astat != 0 && cgstat != 0){ 
   #ifdef LOG_OUT
   safe_pthread_mutex_lock(&con_mutex);
   log_out(gd.fp.con_fd, pd->rec.user, pd->rec.com, pd->rec.data, "", (unsigned char *)gd.ms.inip_addr[pd->rec.fdno]);
   pthread_mutex_unlock(&con_mutex);
   #endif

   stat = file_sets2(pd, (char)0x05, gd.ms.sk[pd->rec.fdno], interval);

   }
else{
   stat = socket_send(gd.ms.sk[pd->rec.fdno], "500 NG No permit.\n", (pd->life.life_int + pd->life.life_los + 15));
   #ifdef LOG_OUT
   safe_pthread_mutex_lock(&con_mutex);
   log_out(gd.fp.con_fd, pd->rec.user, pd->rec.com, pd->rec.data,
     "500 NG No permit.", (unsigned char *)gd.ms.inip_addr[pd->rec.fdno]);
   pthread_mutex_unlock(&con_mutex);
   #endif
   } 

printf("aupl_logi(): %d\n", stat);

return(stat);
}








