コード例 #1
0
ファイル: smtp-server-saml20.c プロジェクト: cktan/toolchain
static void
smtp (FILE * fh, Gsasl * ctx)
{
  char *line = NULL;
  size_t n = 0;
  int rc;

  print (fh, "220 localhost ESMTP GNU SASL smtp-server\n");

  while (gettrimline (&line, &n, fh) >= 0)
    {
      if (strncmp (line, "EHLO ", 5) == 0 || strncmp (line, "ehlo ", 5) == 0)
	{
	  char *mechlist;

	  rc = gsasl_server_mechlist (ctx, &mechlist);
	  if (rc != GSASL_OK)
	    {
	      print (fh, "221 localhost gsasl_server_mechlist (%d): %s\n",
		     rc, gsasl_strerror (rc));
	      goto done;
	    }

	  print (fh, "250-localhost\n");
	  print (fh, "250 AUTH %s\n", mechlist);

	  gsasl_free (mechlist);
	}
      else if (strncmp (line, "AUTH ", 5) == 0
	       || strncmp (line, "auth ", 5) == 0)
	{
	  Gsasl_session *session = NULL;

	  if ((rc = gsasl_server_start (ctx, line + 5, &session)) != GSASL_OK)
	    {
	      print (fh, "221 localhost gsasl_server_start (%d): %s\n",
		     rc, gsasl_strerror (rc));
	      goto done;
	    }

	  server_auth (fh, session);

	  gsasl_finish (session);
	}
      else if (strncmp (line, "QUIT", 4) == 0
	       || strncmp (line, "quit", 4) == 0)
	{
	  print (fh, "221 localhost QUIT\n");
	  goto done;
	}
      else
	print (fh, "500 unrecognized command\n");
    }

  print (fh, "221 localhost getline failure\n");

done:
  free (line);
}
コード例 #2
0
ファイル: server.c プロジェクト: vaibhavvijay/ECE-297
/**
 * @brief Processes commands from client shell and passes them to server_auth, server_get or server_set.
 *
 * @param sock The socket connected to the client.
 * @param cmd The command received from the client.
 * @return Returns 0 on success, 1 otherwise.
 */
int handle_command(int sock, char *cmd)
{
    sprintf(log_buffer, "handle_command: Processing command '%s'\n", cmd);
    logger(server_log, log_buffer); // replace LOG commands with logger() calls
    
    char buf[MAX_CMD_LEN] = {0};

    if(sscanf(cmd, "%s", buf) != 1)
        return 0;    
    else if(strcmp(buf, "AUTH") == 0)
        server_auth(cmd);
    else if(strcmp(buf, "GET") == 0)
    {
        gettimeofday(&start_time, NULL);
        server_get(cmd);
        gettimeofday(&end_time, NULL);
        get_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec);
        fprintf(server_time_log, "get performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec));

    }
    else if(strcmp(buf, "SET") == 0)
    {
        gettimeofday(&start_time, NULL);
        server_set(cmd);
        gettimeofday(&end_time, NULL);
        set_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec);
        fprintf(server_time_log, "storage_set performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec));

    }
    else
        return 1;
    
    // Send back the response to the client.
    sendall(sock, cmd, strlen(cmd));
    sendall(sock, "\n", 1);
    
    return 0;
}
コード例 #3
0
ファイル: lock.c プロジェクト: ArakniD/libDRM
static void server()
{
	int drmfd, tempfd, ret;
	unsigned int client_time, unlock_time;

	drmfd = drm_open_any_master();

	test_lock_unlock(drmfd);
	test_unlock_unlocked(drmfd);
	test_unlock_unowned(drmfd);
	test_open_close_locked(drmfd);

	/* Perform the authentication sequence with the client. */
	server_auth(drmfd);

	/* Now, test that the client attempting to lock while the server
	 * holds the lock works correctly.
	 */
	ret = drmGetLock(drmfd, lock1, 0);
	assert(ret == 0);
	send_event(1, SERVER_LOCKED);
	/* Wait a while for the client to do its thing */
	sleep(1);
	ret = drmUnlock(drmfd, lock1);
	assert(ret == 0);
	unlock_time = get_millis();

	wait_event(1, CLIENT_LOCKED);
	ret = read(commfd[1], &client_time, sizeof(client_time));
	if (ret == -1)
		err(1, "Failure to read client magic");

	if (client_time < unlock_time)
		errx(1, "Client took lock before server released it");

	close(drmfd);
}