Пример #1
0
static int		get_ressources(t_conf *conf,void *req,
				       int in_len, struct sockaddr_in *sa)
{
  int			out_len = -1;
  char			buffer[MAX_HOST_NAME_ENCODED + 1];
  int			len;
  t_packet		*packet;

  if ((len = get_request(req, buffer, conf, sa)) == -1)
    return (-1);
  packet = (void *)&buffer;
  if (! packet->type)
    out_len = build_ressources_reply(conf, req, in_len);
  else
    out_len = login_user(conf, req, buffer, in_len, sa);
  if (out_len == -1)
    {
      MYERROR("parsing error\n");
      return (-1);
    }
  if ((out_len = sendto(conf->sd_udp, req, out_len, 
			0, (struct sockaddr *)sa, sizeof(struct sockaddr))) == -1)
    {
      MYERROR("send error\n");
      return (-1);
    }
  return (0);
 }
Пример #2
0
static int	open_session(t_info *info)
{
  t_rep		rep;

  if (!get_answer(info, &rep))
    {
      info->keep_connected = 0;
      return (0);
    }
  return (login_user(info, &rep));
}
Пример #3
0
int command_execute(int unum)
{
  char *msg = users[unum].ibuf;
  char *cmd;
  struct chatcmd *cmdrec;
  int match = 0;

#ifdef DEBUG
  printf("command_execute: %s\n", msg);
#endif

  /* Validation routine */
  if (users[unum].room == -1) {
    /* MUST give special /! command if not in the room yet */
    if (msg[0] != '/' || msg[1] != '!') return -1;    
    else return (login_user(unum, msg+2));
  }

  /* If not a /-command, it goes to the room. */
  if (msg[0] != '/') {
    chat_allmsg(unum, msg);
    return 0;
  }

  msg++;
  cmd = nextword(&msg);

  /* Look up the command in the chat command table. */
  for (cmdrec = cmdlist; !match && cmdrec->cmdstr != NULL; cmdrec++) {
    if (cmdrec->exact) match = !strcasecmp(cmd, cmdrec->cmdstr);
    else match = !strncasecmp(cmd, cmdrec->cmdstr, strlen(cmd));
    if (match) cmdrec->cmdfunc(unum, msg);
  }

  if (!match) {      
    /* invalid input */
    sprintf(genbuf, "*** Unknown command '/%s'\n", cmd);
    send_to_unum(unum, genbuf, -1);
  }

  memset(users[unum].ibuf, 0, sizeof users[unum].ibuf);
  return 0;
}
Пример #4
0
static void login_command(ostream &out, istream &in)
{
   char username[200] ;
   char password[200] ;
   
   out << "User name: " << flush ;
   in.ignore(1000,'\n') ;
   in.getline(username,sizeof(username)) ;
   out << "Password: "******"Successfully logged in, at access level "
	    << get_access_level() << endl ;
      }
   else if (Fr_errno == ME_PASSWORD)
      cout << "\nUnable to login -- bad password" << endl ;
   else if (Fr_errno == ME_NOTFOUND)
      cout << "\nUnable to login -- unknown user name" << endl ;
   else
      cout << "\nUnable to login (reason unknown)." << endl ;
}
Пример #5
0
/*ケース:接続*/
inline void case_action_connect(CONNECTION_DATA* con){
	REQUEST* req = &con->request;
	FILE* log_file;
	int code;
	USER_INFO* info = req->info;
	//ログイン
	code = login_user(info,req->pass,req->session_id,con->ip);
	if(code == USER_LOGOFF_SUCCESS){//時間切れでログオフ
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Login Error:Time out and Loggoff\n",info->name);
		unlock_log_file();
		//KICK
		connection_return_req_data_header(con,CONNECTION_ACTION_DISCONNECT);
		initCrypt(&info->crypt);//この時点で暗号処理の初期化。
		return;
	}else if(code != USER_LOGIN_SUCCESS){//それ以外でエラー
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"(%s)Login Error:%d\n",info->name,code);
		unlock_log_file();
		//KICK
		connection_return_req_data_header(con,CONNECTION_ACTION_KICKED);
		return;
	}
	//成功
	log_file = lock_log_file();
	time_output();
	ip_output(con->ip);
	fprintf(log_file,"(%s)Login Success\n",info->name);
	unlock_log_file();
	connection_return_req_data_header(con,CONNECTION_ACTION_ACCEPT);
	//次のストリームへ
	nextStream(&info->crypt);
}
int main(void)
{
	int listenfd = 0,connfd = 0, n=0;
	struct sockaddr_in serv_addr;
	struct sockaddr_in peer;
	logged_in = 0;
	char check[1024];
	char sendbuff[1024];
	char buffer[1024];
	char str1[1024], str2[1024];
	int numrv,size, result;
	int max_size = 1024; 
	int closed = 0; 
	int peer_len = sizeof(peer);
	pid_t pid;
	strcpy(str2,"Welcome to Online File Sharing service.\nPlease follow the instruction\n\n");
	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	printf("SERVER successfully launched\n\n");

	memset(&serv_addr, '0', sizeof(serv_addr));
	memset(buffer, '0', sizeof(buffer));    
	serv_addr.sin_family = AF_INET;    
	serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); 
	serv_addr.sin_port = htons(5000);    

	bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));

	if(listen(listenfd, 10) == -1){
		printf("Failed to listen\n");
		return -1;
	}


	while(1)
	{
		if(closed == 1)
			break;

		connfd = accept(listenfd, (struct sockaddr*)NULL ,NULL); // accept awaiting request
		if ( (pid = fork()) == 0 ) {
			close(listenfd);

			sendbuff[0] = '\0'; 
			strcpy(sendbuff,"Connected with server\n");
			size = max_size;	
			sendbuff[22] = '\0';

			if((n=send_mssg(connfd,sendbuff,size))==-1)
			{
				close(connfd);
				break;	
			} 
			if((n=recv_mssg(connfd, buffer, size))==-1)
				exit(1);

			else if(n==0)
				break;			

			query_check(buffer, ip, 1);
			query_check(buffer, port, 2);
			printf("%s: %s", ip, port);					

			while(1){

				if(logged_in == 0) 
				{
					strcpy(str1,"1. New Client: Register (Syntax: \"register <username> <password>\")\n2. Existing Client: Login (Syntax: \"login <username> <password>\")\n3. For closing connection(Syntax: \"close\")\n\n");
					sendbuff[0] = '\0'; 
					strcat(sendbuff,str2);
					strcat(sendbuff,str1);
					size = max_size;	
					sendbuff[strlen(str1)+strlen(str2)-1] = '\0';

					if((n=send_mssg(connfd,sendbuff,size))==-1)
					{
						close(connfd);
						break;	
					} 

					if((n=recv_mssg(connfd, buffer, size))==-1)
						exit(1);

					else if(n==0)
						break;


					if(query_check(buffer, check, 1)<0)
						strcpy(str2,"No such query\n\n");		

					else
					{
						if(strcmp(check,"register")==0)
						{
							result = register_user(buffer);
							if(result == 1)
							{
								strcpy(str2, "Successfully Registered\n\n");
							}

							else
							{
								strcpy(str2, "Unable to Register. Please try again\n\n");

							}

						}

						else if(strcmp(check,"login")==0)
						{
							result = login_user(buffer,connfd);
							if(result == 1)
							{
								strcpy(str2, "Successfully Logged in\n\n");

							}


							else
							{
								strcpy(str2, "Unable to Login. Please try again or register\n\n");

							}
						}	


						else if(strcmp(check,"close")==0)
						{
							close(connfd);
							closed = 1;
							break;	
						}


						else
							strcpy(str2, "No such query\n\n");
					}

				}

				else
				{
					strcpy(str1,"1. Share File (Syntax: \"share <filename> <filepath>\")\n2. Search a file(Syntax: \"search <filename>\")\n3. Logout from server (Syntax: \"logout\")\n\n");
					sendbuff[0] = '\0'; 
					strcat(sendbuff,str2);
					strcat(sendbuff,str1);
					size = max_size;	
					sendbuff[strlen(str1)+strlen(str2)-1] = '\0';
					if((n=send_mssg(connfd,sendbuff,size))==-1)
					{
						close(connfd);
						break;	
					} 

					if((n=recv_mssg(connfd, buffer, size))==-1)
						exit(1);

					else if(n==0)
						break;	

					if(query_check(buffer, check, 1)<0)
						strcpy(str2,"No such query\n\n");		

					else
					{
						if(strcmp(check,"share")==0)
						{
							result = share_file(buffer);
							if(result == 1)
							{
								strcpy(str2, "File successfully shared\n\n");
							}

							else
							{
								strcpy(str2, "Unable to share the file. Please try again\n\n");

							}
						}

						else if(strcmp(check,"search")==0)
						{
							char final_list[1024];
							final_list[0] = '\0';
							result = search_file(buffer, final_list);
							if(result == 1)
							{
								str2[0]='\0';	
								strcat(str2, "Search complete: RESULT: \n\n");
								if(final_list[0]=='\0')
									strcat(str2, "No match Found\n\n");
								else
									strcat(str2, final_list);

							}

							else
							{
								strcpy(str2, "Search failed\n\n");

							}
						}	

						else if(strcmp(check,"logout")==0)
						{
							log_out();	
							logged_in = 0;
							str2[0]='\0';
						}

						else
							strcpy(str2, "No such query\n");
					}


				}

			}
			log_out();
			close(connfd);
			exit(0);
		}         
		close(connfd);

	}


	return 0;
}
Пример #7
0
int
pop_pass (POP *p)
{
    struct passwd  *pw;
    int i;
    int status;

    /* Make one string of all these parameters */

    for (i = 1; i < p->parm_count; ++i)
	p->pop_parm[i][strlen(p->pop_parm[i])] = ' ';

    /*  Look for the user in the password file */
    if ((pw = k_getpwnam(p->user)) == NULL)
	return (pop_msg(p,POP_FAILURE,
			"Password supplied for \"%s\" is incorrect.",
			p->user));

    if (p->kerberosp) {
#ifdef KRB5
	if (p->version == 5) {
	    char *name;

	    if (!krb5_kuserok (p->context, p->principal, p->user)) {
		pop_log (p, POP_PRIORITY,
			 "krb5 permission denied");
		return pop_msg(p, POP_FAILURE,
			       "Popping not authorized");
	    }
	    if(krb5_unparse_name (p->context, p->principal, &name) == 0) {
		pop_log(p, POP_INFO, "%s: %s -> %s",
			p->ipaddr, name, p->user);
		free (name);
	    }
	} else {
	    pop_log (p, POP_PRIORITY, "kerberos authentication failed");
	    return pop_msg (p, POP_FAILURE,
			    "kerberos authentication failed");
	}
#endif
	{ }
    } else {
	 /*  We don't accept connections from users with null passwords */
	 if (pw->pw_passwd == NULL)
	      return (pop_msg(p,
			      POP_FAILURE,
			      "Password supplied for \"%s\" is incorrect.",
			      p->user));

#ifdef OTP
	 if (otp_verify_user (&p->otp_ctx, p->pop_parm[1]) == 0)
	     /* pass OK */;
	 else
#endif
	 /*  Compare the supplied password with the password file entry */
	 if (p->auth_level != AUTH_NONE)
	     return pop_msg(p, POP_FAILURE,
			    "Password supplied for \"%s\" is incorrect.",
			    p->user);
	 else if (!strcmp(crypt(p->pop_parm[1], pw->pw_passwd), pw->pw_passwd))
	     /* pass OK */;
	 else {
	     int ret = -1;
#ifdef KRB5
	     if(ret)
		 ret = krb5_verify_password (p);
#endif
	     if(ret)
		 return pop_msg(p, POP_FAILURE,
				"Password incorrect");
	 }
    }
    status = login_user(p);
    if(status != POP_SUCCESS)
	return status;

    /*  Authorization completed successfully */
    return (pop_msg (p, POP_SUCCESS,
		     "%s has %d message(s) (%ld octets).",
		     p->user, p->msg_count, p->drop_size));
}
Пример #8
0
/*
 * xlogin_user () - login user
 * return : error code or NO_ERROR
 * thread_p (in)  :
 * username (in)  : name of the prepared statement
 */
int
xlogin_user (THREAD_ENTRY * thread_p, const char *username)
{
  return login_user (thread_p, username);
}
Пример #9
0
void
do_login(void)
{
register int i;
register int users;
register char *name;
register struct tm *ltm;
register struct user *tmpuser = 0;
register int wrong = 0;
register char *bbsname;
char pas[9];
char temp[128];
char myname[MAXALIAS + 1];

  printf("\nDOC (Dave's Own version of Citadel) Version 1.71\n\nWelcome to the ISCA BBS.\n\n%s", (bbsname = getenv("BBSNAME")) ? "" : "\nLogin as 'Guest' to just look around, or 'New' to create a new account.\n\n");

  for (;;)
  {
    guest = 0;

    if (!bbsname)
      name = get_name("Name: ", 1);
    else
      strcpy(name = myname, bbsname);

    if (strcmp(name, "New"))
    {
      if ((tmpuser = getuser(name)))
        freeuser(tmpuser);
      if (tmpuser && (!bbsname || tty) && strcmp(name, "Guest"))
        get_string("Password: "******"Incorrect login.\n");
	else
	  printf("There is no user %s on this BBS.\n", name);
        if (++wrong > 3 || bbsname)
        {
	  if (!bbsname)
            printf("\n\nToo many attempts.  Goodbye.\n");
          my_exit(3);
        }
        flush_input(wrong);
        continue;
      }
      else
      {
        xinit();
	if (ouruser->keytime)
	{     
	  printf("\n\n\nYou have not yet registered your validation key...\n\n");
	  dokey(ouruser);
	  if (ouruser->keytime && ouruser->f_trouble)
	  {
	    printf("\n\nYou will need to enter your validation key before you may gain access to the\nBBS.  If you have not yet received your key and think you should, you may send\nE-mail to [email protected].  Please include your BBS username in this\nE-mail so the sysop who receives it knows who you are.  Remember that it can\ntake several days from the time your account was originally created for the\nsysops to validate the information you have provided, if it has been less than\nfour days since you created your account please do not send E-mail yet, as it\nlikely they haven't finished with your account yet.  Impatience won't make them\nwork any faster, and quite likely will make them decide to make you a special\ncase and work slower!  Remember, this BBS is a privilege, not a right.\n\n\n");
	    my_exit(15);
	  }
	}

	printf("\nIowa Student Computer Association BBS.\n");

	if (ouruser->f_deleted)
        {
	  if (ouruser->f_namechanged)
	    printf("\a\nThis account has been marked for deletion because of a request to change the\nusername from '%s' to '%s'.\n\nYou may login as '%s' using the same password.\n\n", ouruser->name, ouruser->reminder, ouruser->reminder);
          else
            printf("\a\nThis account has been marked for deletion, either through your choice or\nbecause you violated ISCA BBS rules by doing something such as providing\nobviously bogus profile info.  You will be logged off.\n\n");
          my_exit(10);
        }
	else if (ouruser->f_inactive)
        {
          printf("You seem to have been denied access to the message system.\n");
          printf("Please contact ISCA (e-mail address [email protected]) for more.\n");
          my_exit(10);
        }


	i = ouruser->time;
        ltm = localtime(&ouruser->time);
        users = add_loggedin(ouruser);

        if (!guest && ouruser->time)
        {
	  printf("Last on: %d/%d/%d %d:%02d ", ltm->tm_mon + 1,
                 ltm->tm_mday, 1900 + ltm->tm_year, ltm->tm_hour, ltm->tm_min);
          ltm = localtime(&ouruser->timeoff);
	  if (ouruser->timeoff >= i)
            printf("until %d:%02d from %s\n", ltm->tm_hour, ltm->tm_min, ouruser->remote);
	  else
	    printf("from %s\n", ouruser->remote);
        }

        strcpy(ouruser->loginname, ARGV[1] && ARGV[2] ? ARGV[2] : "");
        strncpy(ouruser->remote, ARGV[1] ? ARGV[1] : "local", sizeof ouruser->remote - 1);

        if (ouruser->f_noclient)
	{
	  printf("\n\nYou have been disallowed use of the BBS client, you must login using telnet.\n\n");
	  my_exit(10);
	}

	sprintf(temp, "%s %s%s%s/%d", client ? "CLIENT" : "LOGIN", ARGV[1] && ARGV[2] ? ARGV[2] : "", ARGV[1] && ARGV[2] ? "@" : "", ouruser->remote, mybtmp->remport);
	logevent(temp);

	++ouruser->timescalled;

	if (!guest)
	  printf("This is call %d.  There are %d users.\n", ouruser->timescalled, users);
        if (ouruser->f_aide)
           validate_users(0);

	/*
	 * Turn off expresses and tell the user this was done if user is
	 * configured for this 
	 */
	if (!guest && mybtmp->xstat)
	  printf("\nNOTE:  You have eXpress messages turned OFF as a default!\n");
        if (mybtmp->elf)
          printf("\nYou are marked as available to help others.\n");

	checkmail(FALSE);

	termset();

        if (*ouruser->reminder)
        {
          printf("\n\aREMINDER:\n%s\n\n", ouruser->reminder);
          printf("Please hit 'Y' to acknowledge having seen this reminder -> ");
          get_single_quiet("yY");
        }

	if (ouruser->f_badinfo || ouruser->f_duplicate)
	{
	  help("badinfo", NO);
	  mysleep(300);
	}

	if (guest)
	{
	  help("guestwelcome", NO);
	  hit_return_now();
	}
	return;
      }
    }
    else
      if (!(i = new_user()))
      {
	printf("\n\nSorry, there was some problem setting up your BBS account.\n\nPlease try again later.\n\n");
        my_exit(10);
      }
      else if (i > 0)
        return;
  }
}
Пример #10
0
void *client_handler(void *fd) {
        struct THREAD_INFO thread_info = *(struct THREAD_INFO *) fd;
        int bytes;
        struct PACKET packet;

        while(1) {
                bytes = recv(thread_info.sockfd,  (void *)&packet, sizeof(struct PACKET), 0);
                if (!bytes) {
                        perror("No bytes received at server");
                        exit(0);
                }
                printf("opt:%s %d\n",packet.option, strcmp(packet.option, "list"));

                if (strcmp(packet.option, "login") == 0 ) {
                        login_user(&local_user, packet.alias, thread_info.sockfd);
                        printf("here\n");
                        printf("user: %s loged in\n",packet.alias);
                        continue;
                }
                else if (strcmp(packet.option, "pm") == 0) {
                        printf("pm\n");
                        User *temp_user = &local_user;
                        int user_fd = thread_info.sockfd;
                        int found = 0;
                        while(temp_user->next != NULL) {
                                temp_user = temp_user->next;
                                if (strcmp(packet.connectTo, temp_user->name) == 0) {
                                        user_fd = temp_user->fd;
                                        found = 1;
                                        break;
                                }
                        }
                        if (found == 0) {
                                strcpy(packet.buff, "no such user exists\n");
                        }
                        printf("f%s\n",packet.alias);

                        if(send(user_fd, (void *)&packet, sizeof(struct PACKET), 0) < 0) {
                                perror("Send to client error");
                                exit(1);
                        }
                        continue;
                }
                else if (strcmp(packet.option, "all") == 0) {
                        printf("all\n");
                        User *temp_user = &local_user;
                        int user_fd = thread_info.sockfd;
                        int found = 0;
                        while(temp_user->next != NULL) {
                                temp_user = temp_user->next;
                                if (strcmp(packet.alias, temp_user->name) != 0) {
                                        if(send( temp_user->fd, (void *)&packet, sizeof(struct PACKET), 0) < 0) {
                                                perror("Send to client error");
                                                exit(1);
                                        }
                                }
                        }
                        continue;
                }
                else if (strcmp(packet.option, "list") == 0 ) {
                        printf("looking at list");
                        User *temp_user = &local_user;
                        char name_list[1024];
                        int iterator = 1;
                        name_list[0] = '\n';
                        while(temp_user->next != NULL) {
                                temp_user = temp_user->next;
                                printf("%s\n",temp_user->name);
                                for(int i = 0; i < strlen(temp_user->name); i++) {
                                        name_list[i+iterator] = temp_user->name[i];
                                }
                                name_list[strlen(temp_user->name)+iterator] = '\n';
                                iterator += strlen(temp_user->name) + 1;
                        }

                        strcpy(packet.buff, name_list);
                        strcpy(packet.alias, "server");

                        if(send(thread_info.sockfd, (void *)&packet, sizeof(struct PACKET), 0) < 0) {
                                perror("Send to client error");
                                exit(1);
                        }
                        continue;
                }
                else {
                        printf("no decent option sent");
                }

        }
}