Exemple #1
0
void
quot(char *name, char *mp)
{
	int fd;

	get_inode(-1, NULL, 0);		/* flush cache */
	inituser();
	initfsizes();
	if ((fd = open(name,0)) < 0
	    || lseek(fd,SBOFF,0) != SBOFF
	    || read(fd,superblock,SBSIZE) != SBSIZE) {
		warn("%s", name);
		close(fd);
		return;
	}
	if (((struct fs *)superblock)->fs_magic != FS_MAGIC) {
		warnx("%s: not a BSD filesystem",name);
		close(fd);
		return;
	}
	printf("%s:",name);
	if (mp)
		printf(" (%s)",mp);
	putchar('\n');
	(*func)(fd,(struct fs *)superblock,name);
	close(fd);
}
Exemple #2
0
void
quot(char *name, char *mp)
{
	int fd;
	struct fs *fs;

	get_inode(-1, NULL, 0);		/* flush cache */
	inituser();
	initfsizes();
	if ((fd = open(name,0)) < 0) {
		warn("%s", name);
		close(fd);
		return;
	}
	switch (sbget(fd, &fs, -1)) {
	case 0:
		break;
	case ENOENT:
		warn("Cannot find file system superblock");
		close(fd);
		return;
	default:
		warn("Unable to read file system superblock");
		close(fd);
		return;
	}
	printf("%s:",name);
	if (mp)
		printf(" (%s)",mp);
	putchar('\n');
	(*func)(fd, fs, name);
	close(fd);
}
Exemple #3
0
/* initialisation of the library */
void
init(){
    openlog ("libnosync", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    inituser();
    initprocess();
    syslog (LOG_NOTICE, "loaded by program %s, user %s", process, user);
    initsymbols();
    readconfig();
}
Exemple #4
0
void
quot(char *name, char *mp)
{
	int i, fd;
	struct fs *fs;

	get_inode(-1, NULL, 0);		/* flush cache */
	inituser();
	initfsizes();
	/*
	 * XXX this is completely broken.  Of course you can't read a
	 * directory, well, not anymore.  How to fix this, though...
	 */
	if ((fd = open(name, 0)) < 0) {
		warn("%s", name);
		return;
	}
	for (i = 0; sblock_try[i] != -1; i++) {
		if (lseek(fd, sblock_try[i], 0) != sblock_try[i]) {
			close(fd);
			return;
		}
		if (read(fd, superblock, SBLOCKSIZE) != SBLOCKSIZE) {
			close(fd);
			return;
		}
		fs = (struct fs *)superblock;
		if ((fs->fs_magic == FS_UFS1_MAGIC ||
		    (fs->fs_magic == FS_UFS2_MAGIC &&
		    fs->fs_sblockloc == sblock_try[i])) &&
		    fs->fs_bsize <= MAXBSIZE &&
		    fs->fs_bsize >= sizeof(struct fs))
			break;
	}
	if (sblock_try[i] == -1) {
		warnx("%s: not a BSD filesystem", name);
		close(fd);
		return;
	}
	ffs_oldfscompat(fs);
	printf("%s:", name);
	if (mp)
		printf(" (%s)", mp);
	putchar('\n');
	(*func)(fd, fs, name);
	close(fd);
}
Exemple #5
0
void
quot(char *name, char *mp)
{
	int i, fd;
	struct fs *fs;

	get_inode(-1, NULL, 0);		/* flush cache */
	inituser();
	initfsizes();
	if ((fd = open(name,0)) < 0) {
		warn("%s", name);
		close(fd);
		return;
	}
	for (i = 0; sblock_try[i] != -1; i++) {
		if (lseek(fd, sblock_try[i], 0) != sblock_try[i]) {
			close(fd);
			return;
		}
		if (read(fd, superblock, SBLOCKSIZE) != SBLOCKSIZE) {
			close(fd);
			return;
		}
		fs = (struct fs *)superblock;
		if ((fs->fs_magic == FS_UFS1_MAGIC ||
		     (fs->fs_magic == FS_UFS2_MAGIC &&
		      fs->fs_sblockloc == sblock_try[i])) &&
		    fs->fs_bsize <= MAXBSIZE &&
		    fs->fs_bsize >= sizeof(struct fs))
			break;
	}
	if (sblock_try[i] == -1) {
		warnx("%s: not a BSD filesystem",name);
		close(fd);
		return;
	}
	printf("%s:",name);
	if (mp)
		printf(" (%s)",mp);
	putchar('\n');
	(*func)(fd, fs, name);
	close(fd);
}
Exemple #6
0
static size_t loaduser( void )
{
   FILE *stream;
   struct UserTable *userp;
   size_t subscript;
   char *token;

/*--------------------------------------------------------------------*/
/*     First, load in the active user as first user in the table      */
/*--------------------------------------------------------------------*/

   userp = inituser( E_mailbox );
   userp->realname = E_name;
   userp->homedir  = E_homedir;

/*--------------------------------------------------------------------*/
/*       Password file format:                                        */
/*          user id:password:::user/system name:homedir:shell         */
/*--------------------------------------------------------------------*/

   if ((stream = FOPEN(E_passwd, "r",TEXT_MODE)) == NULL)
   {
      if ( debuglevel > 2 )
         printerr( E_passwd );

      users = realloc(users, userElements *  sizeof(*users));

      checkref(users);
      return userElements;
   } /* if */

   PushDir( E_confdir );      /* Use standard reference point for     */
                              /* for directories                      */

/*--------------------------------------------------------------------*/
/*                 The password file is open; read it                 */
/*--------------------------------------------------------------------*/

   while (! feof(stream))
   {
      char buf[BUFSIZ];

      if (fgets(buf,BUFSIZ,stream) == NULL)   /* Try to read a line   */
         break;               /* Exit if end of file                  */

      if ((*buf == '#') || (*buf == '\0'))
         continue;            /* Line is a comment; loop again        */

      if ( buf[ strlen(buf) - 1 ] == '\n')
         buf[ strlen(buf) - 1 ] = '\0';

      token = NextField(buf);

      if (token    == NULL)   /* Any data?                            */
         continue;            /* No --> read another line             */

      userp = inituser(token);/* Initialize record for user           */

      if ( userp->uid == NULL )
      {
         panic();
      }

      if (userp->password != NULL)  /* Does the user already exist?   */
      {                       /* Yes --> Report and ignore            */

         printmsg(0,"loaduser: Duplicate entry for '%s' in '%s' ignored",
               token,E_passwd);
         continue;            /* System already in /etc/passwd,
                                 ignore it.                           */
      }

/*--------------------------------------------------------------------*/
/*       Password fields are funny; if the tokenize field function    */
/*       is returns NULL, we set the password to the comparable       */
/*       empty string ("").  But if the password is if asterisk       */
/*       (*), we leave the password NULL, and the user can never      */
/*       login remotely.                                              */
/*--------------------------------------------------------------------*/

      token = NextField(NULL);   /* Get the user password             */

      if ( token == NULL )       /* No password needed for login?     */
      {
         printmsg(2,"loaduser: WARNING: No password assigned for user %s",
                     userp->uid );
         userp->password = "";   /* Assign requested password        */
      }
      else if (!equal(token,"*")) /* User can login with passwd?      */
         userp->password = newstr(token); /* Yes --> Set password     */

      token = NextField(NULL);   /* Use  UNIX user number as tone     */
                                 /* to beep at                        */
      if (token != NULL)
         userp->beep = newstr( token );

      token = NextField(NULL);   /* UNIX group number                 */

      if (token != NULL)         /* Did they provide a group?         */
         userp->group = newstr(token); /* Yes --> Copy                */

      token = NextField(NULL);   /* Get the formal user name          */

      if (token != NULL)         /* Did they provide user name?       */
         userp->realname = newstr(token); /* Yes --> Copy             */

      token = NextField(NULL);   /* Get home directory (optional)     */

      if ( token != NULL)
      {
         userp->homedir = newstr(normalize( token ));
         if ( equal( userp->uid, E_mailbox ))
            E_homedir = userp->homedir;
      }

      token = NextField(NULL);   /* Get user shell (optional)         */

      if ( token != NULL )       /* Did we get it?                    */
         userp->sh = newstr(token); /* Yes --> Copy it in             */

   }  /* while */

   PopDir();

   fclose(stream);
   users = realloc(users, userElements *  sizeof(*users));
   checkref(users);

   qsort(users, userElements ,sizeof(users[0]) , usercmp);

   for (subscript = 0 ; subscript < userElements; subscript ++)
   {
      KWBoolean duplicate = KWFalse;

      if ( subscript && equali( users[subscript].uid,
                                users[subscript- 1 ].uid))
      {
         printmsg(0,"*error* The user id \"%s\" occurs more than once in %s!"
                    "  Delete extra entries!",
                     users[subscript-1].uid,
                     E_passwd );

         duplicate = KWTrue;
      }

      printmsg(duplicate ? 0: 8,
                 "loaduser: user[%d]\tlogin(%s)\tno(%s)\tgroup(%s)"
                 "\tname(%s)\thome(%s)\tshell(%s)",
         subscript,
         users[subscript].uid,
         users[subscript].beep == NULL ? "NONE" : users[subscript].beep,
         users[subscript].group,
         users[subscript].realname,
         users[subscript].homedir,
         users[subscript].sh);
   } /* for */

   return userElements;

} /* loaduser */
Exemple #7
0
int main(int argc, char **argv)
{
	int sockfd, new_fd;
    	socklen_t len;
	SSL *ssl;
	struct user *node;
    	struct sockaddr_in my_addr, their_addr;
    	unsigned int myport,lisnum;
    	int result;	
	result = pthread_mutex_init(&work_mutex,NULL);//initialize the mutex    
	if (argv[1])
		myport = atoi(argv[1]);
	else
        	myport = 7838;

    	if (argv[2])
        	lisnum = atoi(argv[2]);
    	else
        	lisnum = LISNUM;  //the max number of connected client

    	/*SSl initialize*/
    	SSL_library_init();    
    	OpenSSL_add_all_algorithms(); /*load algorithms of SSL*/    
    	SSL_load_error_strings();     /*load error infor*/
    	/*create a ssl_ctx */
    	ctx = SSL_CTX_new(SSLv23_server_method());
    	if(ctx == NULL) {
        	ERR_print_errors_fp(stdout);
        	exit(1);
    	}
    	/*certificate the user's ctx*/
    	if(SSL_CTX_use_certificate_file(ctx, argv[4], SSL_FILETYPE_PEM) <= 0) {
        	ERR_print_errors_fp(stdout);
        	exit(1);
    	}
    	/*load privatekey*/
    	if(SSL_CTX_use_PrivateKey_file(ctx, argv[5], SSL_FILETYPE_PEM) <= 0) {
        	ERR_print_errors_fp(stdout);
        	exit(1);
    	}
    	/*certificate privatekey*/
    	if(!SSL_CTX_check_private_key(ctx)) {
        	ERR_print_errors_fp(stdout);
        	exit(1);
    	}

    	/*create a socket*/
    	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
        	perror("socket");
        	exit(1);
    	}else
        	printf("socket created\n");

    	bzero(&my_addr, sizeof(my_addr));
    	my_addr.sin_family = AF_INET;
    	my_addr.sin_port = htons(myport);
    	if (argv[3])
        	my_addr.sin_addr.s_addr = inet_addr(argv[3]);
    	else
        	my_addr.sin_addr.s_addr = INADDR_ANY;

    	if (bind(sockfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr))
        == -1) {
        	perror("bind");
        	exit(1);
    	} else
        	printf("binded\n");

    	if (listen(sockfd, LISNUM) == -1) {
        	perror("listen");
        	exit(1);
    	} else
        	printf("begin listen\n");
	/*initialize signal*/
	sigemptyset(&set);
	sigaddset(&set,SIGUSR1);
	sigaddset(&set,SIGUSR2);
	sigprocmask(SIG_SETMASK,&set,NULL);
	inituser(&root);  //初始化用户链表        
	while (1) {
       		len = sizeof(struct sockaddr);
        	/*accept connection*/
        	if ((new_fd =
             		accept(sockfd, (struct sockaddr *) &their_addr,
                    	&len)) == -1) {
            			perror("accept");
            			exit(errno);
        	}else{
              		printf("server: got connection from %s, port %d, socket %d\n",inet_ntoa(their_addr.sin_addr),ntohs(their_addr.sin_port), new_fd);
			/*create a new ssl*/
       			ssl = SSL_new(ctx);
			/*combinate the ssl with asocket*/
        		SSL_set_fd(ssl, new_fd);
       	 		/*create a safe connection*/
        		if (SSL_accept(ssl) == -1) {
            			perror("accept");
            			break;
        		}
	         	/*create a thread to solve the communication*/
		node = beforechat(&ssl);
		pthread_mutex_lock(&work_mutex); 
 		result = pthread_create(thread+(count++),NULL,recv_data,node);
		r_thread = thread[count-1];
		pthread_kill(r_thread,SIGUSR1);
 		//pthread_create(thread+(count++),NULL,send_data,ssl);
		if(result !=0){
			perror("pthread_create");
			exit(EXIT_FAILURE);
		}
		//send_data(ssl);
		pthread_mutex_unlock(&work_mutex);
	}
       }
    if(ssl != NULL)
    {
	SSL_shutdown(ssl);
    	SSL_free(ssl);
    }
    close(sockfd);
    SSL_CTX_free(ctx);
    return 0;
}
Exemple #8
0
void
bbsstart(void)
{
unsigned char stdinbuf[STDINBUFSIZ];
long    uglastmsg;	/* last msg seen in prev. rm */
long    ugtemp = TWILIGHTZONE;
short   prev_rm = TWILIGHTZONE;
char    cit_cmd;
char    bueller = 0;

  room = &sroom;
  setvbuf(stdin, (char *)stdinbuf, _IOFBF, STDINBUFSIZ);
  setvbuf(stdout, (char *)stdoutbuf, _IOFBF, STDOUTBUFSIZ);

  init_system();
  /* Putty.exe is obstinate */
  /* IAC WILL SGA */
  putchar(IAC); putchar(WILL); putchar(TELOPT_SGA);
  /* magic to set telnet into character mode */
  /* IAC  DO LINEMODE, IAC WILL ECHO */
  write(1,"\377\375\042\377\373\001",6);
  /* let window sizes come through */
  /* IAC DO NAWS */
  write(1,"\377\375\037",3);

  reserve_slot();
  do_login();

  colorize("\n@G");

  curr = LOBBY_RM_NBR;
  inituser();

  openroom();
  storeug(&uglastmsg, &ugtemp);

  /* The first thing we do is make the user read the lobby */
  cit_cmd = 'N';

  readroom(cit_cmd);


  for(;;)
  {
    /*
     * check if user has been kicked out of this room while they were in it,
     * or if room was deleted
     */
    if (ouruser->generation[curr] < 0 || !msg->room[curr].flags)
    {
      curr = LOBBY_RM_NBR;
      openroom();
      storeug(&uglastmsg, &ugtemp);
    }

    if (cit_cmd)
      colorize("\n@Y%s>@G ", msg->room[curr].name);

    checkx(0);

    if (ouruser->f_prog)
      cit_cmd = get_single_quiet("ABCD\005eEFGHIJKLNOpPqQRsSTUvVwWxX\027\030yYZ /?#%@-\"");
    else if (ouruser->f_aide)
      cit_cmd = get_single_quiet("ABC\005eEFGHIJKLNOpPqQRsSTUvVwWxX\027\030yYZ /?#%@-\"");
    else if (ouruser->usernum == msg->room[curr].roomaide && !ouruser->f_twit)
      cit_cmd = get_single_quiet("ABC\005eEFGHIJKLNOpPqQRsSTUwWxX\027\030yYZ /?#%-\"");
    else
      cit_cmd = get_single_quiet("BCeEFGHIJKLNOpPqQRsSTUwWxX\027\030yYZ /?#%-\"");

    if (cit_cmd == SP)
      cit_cmd = 'N';

    if (guest && !strchr("BFGHIJKLNOpPRsSTUwWyY/?#-", cit_cmd))
    {
      colorize("\n\n@RThe Guest user cannot do that.@G\n");
      continue;
    }

    if (curr == LOBBY_RM_NBR && strchr("DGNqsTU\027X\030Z% ", cit_cmd))
    {
      if (bueller++ >= 12)
        flush_input(bueller / 25);
      if (bueller >= 100)
      {
        colorize("@R\n\n\nGo away until you have something useful to do!\n\n\n@G");
        my_exit(10);
      }
    }
    else
      bueller = 0;

    if (strchr("AC\005eEHJpPQSvVx\030yYZ#-\"", cit_cmd))
      mybtmp->nox = 1;

    switch (cit_cmd)
    {

      case 'A':
	printf("Sysop commands (%s)\n", msg->room[curr].name);
	aide_menu();
	break;

      case 'R':
      case 'B':
	cit_cmd = 'R';
	printf("Read Reverse\n");
	readroom(cit_cmd);
	break;

      case 'C':
        printf("Change config\n");
        change_setup(NULL);
	break;

      case 'D':
	printf("Debug\n");
	debug();
	break;

      case '\005':
	if (ouruser->usernum == msg->room[curr].roomaide)
	{
	  printf("Enter Forum Moderator message\n\nAre you sure you want to enter a message as Forum Moderator? (Y/N) -> ");
	  if (!yesno(-1))
	    break;
	  sysopflags |= SYSOP_FROM_FM;
	}
	else if (ouruser->f_admin)
        {
	  printf("Enter Sysop message\n\nNOTE: You are entering this message as Sysop!\n\n");
	  sysopflags |= SYSOP_FROM_SYSOP;
        }
	/* FALL THRU */

      case 'e':
      case 'E':
	{
	  char work[20];

	  if (ouruser->f_newbie && (curr == MAIL_RM_NBR || curr > 4))
	    help("newuseraccess", NO);
	  else
	  {
	    if (cit_cmd == 'E')
	      printf("Upload message\n\n");
	    else if (cit_cmd == 'e')
	      printf("Enter message\n\n");
	    *work = 0;
	    (void)entermessage(curr, work, cit_cmd == 'e' ? 0 : 2);
	    sysopflags &= ~(SYSOP_FROM_SYSOP | SYSOP_FROM_FM);
	  }
	}
	break;

      case 'F':
	printf("Read Forward\n");
	readroom(cit_cmd);
	break;

      case 'G':
	printf("Goto ");
	updatels(&prev_rm);
	/* find next room with unread msgs and open it */
	nextroom();
	openroom();
	storeug(&uglastmsg, &ugtemp);
	break;

      case 'H':
	printf("Help!\n");
	help("topics", YES);
	break;

      case 'q':
      case 'Q':
        get_syself_help(cit_cmd);
        break;

      case 'I':
	printf("Forum Info\n");
	readdesc();
	break;

      case 'J':
	{
	  int old_rm;

	  printf("Jump to ");
	  old_rm = curr;
	  if (findroom() == YES)
	  {
	    int save_rm;
  
            mybtmp->nox = 0;
	    save_rm = curr;
	    curr = old_rm;
	    updatels(&prev_rm);
	    curr = save_rm;
	    openroom();
	    storeug(&uglastmsg, &ugtemp);
	  }
	}
	break;

      case 'K':
	printf("Known forums and zapped list\n");
	knrooms();
	break;

      case 'L':
        dologout();
	break;

      case 'N':
	if (ouruser->lastseen[curr] < room->num[MSGSPERRM - 1])
	{
	  printf("Read New\n");
	  readroom(cit_cmd);
	}
	else
	{			/* No new notes so just do a Goto now */
	  printf("Goto ");
	  updatels(&prev_rm);
	  /* find next room with unread msgs and open it */
	  nextroom();
	  openroom();
	  storeug(&uglastmsg, &ugtemp);
	}
	break;

      case 'O':
	printf("Read Old messages reverse\n");
	readroom(cit_cmd);
	break;

      case 'p':
      case 'P':
	profile_user(cit_cmd == 'P');
	break;

      case 's':		/* don't update lastseen, you're skipping the room */
	printf("Skip %s\n", msg->room[curr].name);
	skipping[curr >> 3] |= 1 << (curr & 7);
	/* after skipping a room, find the next unread room (not a goto) */
	nextroom();
	openroom();
	ugtemp = ouruser->lastseen[curr];
	break;

      case 'S':
	{
	  int old_rm;

	  printf("Skip %s to ", msg->room[curr].name);
	  old_rm = curr;
	  if (findroom() == YES)
	  {
            mybtmp->nox = 0;
	    skipping[old_rm >> 3] |= 1 << (old_rm & 7);
	    openroom();
	    ugtemp = ouruser->lastseen[curr];
	  }
	}
	break;

      case 'T':
	printdate("Time\n\n%s");
	break;

      case 'U':
	printf("Ungoto\n");
	ungoto(prev_rm, &uglastmsg, &ugtemp);
	break;

      case 'v':
	cit_cmd = 0;
	break;

      case 'V':
	printf("Validate new users\n");
	validate_users(1);
	break;

      case '\027':
	if (client)
	  clientwho();
	else
	  cit_cmd = 0;
	break;

      case 'w':		/* Short form of who's online */
	show_online(3);
	break;

      case 'W':		/* Who's online */
	show_online(0);
	break;

      case 'x':
	express();
	break;

      case 'X':
	change_express(1);
	break;

      case CTRL_X:
	old_express();
	break;

      case 'y':
      case 'Y':
        if (!wanttoyell(cit_cmd))
          break;
	(void)entermessage(-1, "", cit_cmd == 'y' ? 0 : 2);
	break;

      case 'Z':
	printf("Zap forum\n");
	if (forgetroom())
        {
	  nextroom();
	  openroom();
	  ugtemp = ouruser->lastseen[curr];
        }
	break;

      case '?':
      case '/':
	if (guest)
	  help("guestforumlevel", NO);
	else
	  help("doccmd", NO);
	break;

      case '#':
	readroom(cit_cmd);
	break;

      case '%':
	if (ouruser->f_elf && !ouruser->f_restricted && !ouruser->f_twit)
          if (mybtmp->xstat && !mybtmp->elf)
            printf("\n\nYou can't enable yourself as a guide while your X's are disabled.\n");
	  else if ((mybtmp->elf = !mybtmp->elf))
	    printf("\n\nYou are now marked as being available to help others.\n");
	  else
	    printf("\n\nYou are no longer marked as being available to help others.\n");
	else
	  cit_cmd = 0;
	break;

      case '-':
	readroom(cit_cmd);
	break;

      case '@':
	printf("Sysops, programmers, and forum moderators\n");
	more(AIDELIST, 0);
	break;

      case '"':
	{
	  char work[20];

	  printf("Quote X messages to Sysop\n");
          *work = 0;
          (void)entermessage(-1, work, -1);
	}
	break;

      default:
	break;
    }				/* switch */

  }