예제 #1
0
void
test_change_unix_socket_group (void)
{
    const gchar *path;
    struct stat stat_buffer;
    gint i, n_groups, max_n_groups;
    gid_t *groups;
    struct group *group = NULL;
    GError *error = NULL;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    max_n_groups = getgroups(0, NULL);
    if (max_n_groups < 0)
        max_n_groups = 5;

    groups = g_new0(gid_t, max_n_groups);
    cut_take_memory(groups);

    n_groups = getgroups(max_n_groups, groups);
    if (n_groups == -1)
        cut_assert_errno();

    for (i = 0; i < n_groups; i++) {
        if (groups[i] == getegid())
            continue;

        errno = 0;
        group = getgrgid(groups[i]);
        if (!group) {
            if (errno == 0)
                cut_omit("can't find supplementary group: %u", groups[i]);
            else
                cut_assert_errno();
        }
    }

    if (!group)
        cut_omit("no supplementary group");

    milter_client_set_default_unix_socket_group(client, group->gr_name);
    milter_client_set_default_remove_unix_socket_on_close(client, FALSE);

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    if (stat(path, &stat_buffer) == -1)
        cut_assert_errno();

    cut_assert_equal_uint(group->gr_gid, stat_buffer.st_gid);
}
void
cut_setup (void)
{
    config = milter_manager_configuration_new(NULL);
    loop = milter_test_event_loop_new();

    egg = NULL;
    another_egg = NULL;
    condition = NULL;

    expected_children = milter_manager_children_new(config, loop);
    actual_children = NULL;

    expected_load_paths = NULL;

    expected_eggs = NULL;
    expected_applicable_conditions = NULL;

    actual_xml = NULL;

    tmp_dir = g_build_filename(milter_test_get_base_dir(),
                               "tmp",
                               NULL);
    cut_remove_path(tmp_dir, NULL);
    if (g_mkdir_with_parents(tmp_dir, 0700) == -1)
        cut_assert_errno();
}
예제 #3
0
void
cut_setup(void)
{
  GError *error = NULL;
  memcached_return rc;

  tmp_directory = g_build_filename(grn_test_get_base_dir(), "tmp", NULL);
  cut_remove_path(tmp_directory, NULL);
  if (g_mkdir_with_parents(tmp_directory, 0700) == -1) {
    cut_assert_errno();
  }

  egg = gcut_egg_new(GROONGA, "-s",
                     "-p", GROONGA_TEST_PORT,
                     cut_take_printf("%s%s%s",
                                     tmp_directory,
                                     G_DIR_SEPARATOR_S,
                                     "memcached.db"),
                     NULL);
  gcut_egg_hatch(egg, &error);
  gcut_assert_error(error);

  sleep(1); /* wait for groonga daemon */
  memc = memcached_create(NULL);
  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);

  servers = memcached_servers_parse("localhost:" GROONGA_TEST_PORT);
  rc = memcached_server_push(memc, servers);

  cut_set_message("memcached server connect failed.");
  cut_assert_equal_int(MEMCACHED_SUCCESS, rc);

  memcached_flush(memc, 0); /* flush immediately for debug daemon */
}
MilterTestClient *
milter_test_client_new (const gchar *spec, MilterDecoder *decoder,
                        MilterEventLoop *loop)
{
    MilterTestClientPrivate *priv;
    gint domain;
    struct sockaddr *address;
    socklen_t address_size;
    MilterTestClient *client;
    gint fd;
    gboolean reuse_address = TRUE;
    GError *error = NULL;

    milter_connection_parse_spec(spec, &domain, &address, &address_size, &error);
    gcut_assert_error(error);

    fd = socket(domain, SOCK_STREAM, 0);
    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
               &reuse_address, sizeof(reuse_address));

    if (bind(fd, address, address_size) == -1 ||
        listen(fd, 5) == -1) {
        close(fd);
        cut_assert_errno();
    }

    client = g_object_new(MILTER_TEST_TYPE_CLIENT, NULL);

    priv = MILTER_TEST_CLIENT_GET_PRIVATE(client);

    priv->decoder = g_object_ref(decoder);
    priv->loop = g_object_ref(loop);

    priv->fd = fd;
    priv->channel = g_io_channel_unix_new(priv->fd);
    priv->watch_id = -1;

    g_io_channel_set_close_on_unref(priv->channel, TRUE);
    if (!g_io_channel_set_encoding(priv->channel, NULL, &error) ||
        !g_io_channel_set_flags(priv->channel,
                                G_IO_FLAG_NONBLOCK | G_IO_FLAG_IS_READABLE,
                                &error)) {
        g_object_unref(client);
        gcut_assert_error(error);
    }
    priv->watch_id = milter_event_loop_watch_io(priv->loop,
                                                priv->channel,
                                                G_IO_IN | G_IO_PRI |
                                                G_IO_ERR | G_IO_HUP | G_IO_NVAL,
                                                watch_func, client);

    return client;
}
MilterTestServer *
milter_test_server_new (const gchar *spec, MilterDecoder *decoder,
                        MilterEventLoop *loop)
{
    MilterTestServerPrivate *priv;
    gint domain;
    struct sockaddr *address;
    socklen_t address_size;
    MilterTestServer *server;
    gint fd;
    GError *error = NULL;

    milter_connection_parse_spec(spec, &domain, &address, &address_size, &error);
    gcut_assert_error(error);

    fd = socket(domain, SOCK_STREAM, 0);

    if (connect(fd, address, address_size) == -1) {
        close(fd);
        cut_assert_errno();
    }

    server = g_object_new(MILTER_TEST_TYPE_SERVER, NULL);

    priv = MILTER_TEST_SERVER_GET_PRIVATE(server);

    priv->decoder = g_object_ref(decoder);
    priv->loop = g_object_ref(loop);

    priv->fd = fd;
    priv->channel = g_io_channel_unix_new(priv->fd);
    priv->watch_id = -1;

    g_io_channel_set_close_on_unref(priv->channel, TRUE);
    if (!g_io_channel_set_encoding(priv->channel, NULL, &error) ||
        !g_io_channel_set_flags(priv->channel,
                                G_IO_FLAG_NONBLOCK |
                                G_IO_FLAG_IS_READABLE |
                                G_IO_FLAG_IS_WRITEABLE,
                                &error)) {
        g_object_unref(server);
        gcut_assert_error(error);
    }
    priv->watch_id = milter_test_io_add_decode_watch(priv->loop,
                                                     priv->channel,
                                                     priv->decoder);

    return server;
}
예제 #6
0
void
setup (void)
{
    actual_address = NULL;
    actual_address_size = 0;

    expected_error = NULL;
    actual_error = NULL;

    tmp_dir = g_build_filename(milter_test_get_base_dir(),
                               "tmp",
                               NULL);
    cut_remove_path(tmp_dir, NULL);
    if (g_mkdir_with_parents(tmp_dir, 0700) == -1)
        cut_assert_errno();
}
예제 #7
0
void
test_change_unix_socket_mode (void)
{
    const gchar *path;
    struct stat stat_buffer;
    GError *error = NULL;

    path = cut_take_printf("%s/milter.sock", tmp_dir);
    spec = cut_take_printf("unix:%s", path);

    milter_client_set_default_unix_socket_mode(client, 0666);
    milter_client_set_default_remove_unix_socket_on_close(client, FALSE);

    cut_trace(setup_client());
    milter_client_run(client, &error);
    gcut_assert_error(error);

    if (stat(path, &stat_buffer) == -1)
        cut_assert_errno();

    cut_assert_equal_uint(S_IFSOCK | 0666, stat_buffer.st_mode);
}