106a99fe3SHajimu UMEMOTO /*- 206a99fe3SHajimu UMEMOTO * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 306a99fe3SHajimu UMEMOTO * All rights reserved. 406a99fe3SHajimu UMEMOTO * 506a99fe3SHajimu UMEMOTO * Redistribution and use in source and binary forms, with or without 606a99fe3SHajimu UMEMOTO * modification, are permitted provided that the following conditions 706a99fe3SHajimu UMEMOTO * are met: 806a99fe3SHajimu UMEMOTO * 1. Redistributions of source code must retain the above copyright 906a99fe3SHajimu UMEMOTO * notice, this list of conditions and the following disclaimer. 1006a99fe3SHajimu UMEMOTO * 2. Redistributions in binary form must reproduce the above copyright 1106a99fe3SHajimu UMEMOTO * notice, this list of conditions and the following disclaimer in the 1206a99fe3SHajimu UMEMOTO * documentation and/or other materials provided with the distribution. 1306a99fe3SHajimu UMEMOTO * 1406a99fe3SHajimu UMEMOTO * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1506a99fe3SHajimu UMEMOTO * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1606a99fe3SHajimu UMEMOTO * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1706a99fe3SHajimu UMEMOTO * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1806a99fe3SHajimu UMEMOTO * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1906a99fe3SHajimu UMEMOTO * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2006a99fe3SHajimu UMEMOTO * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2106a99fe3SHajimu UMEMOTO * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2206a99fe3SHajimu UMEMOTO * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2306a99fe3SHajimu UMEMOTO * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2406a99fe3SHajimu UMEMOTO * SUCH DAMAGE. 2506a99fe3SHajimu UMEMOTO */ 2606a99fe3SHajimu UMEMOTO 27db1bdf2bSMichael Bushkov #ifndef __NSCD_QUERY_H__ 28db1bdf2bSMichael Bushkov #define __NSCD_QUERY_H__ 2906a99fe3SHajimu UMEMOTO 3006a99fe3SHajimu UMEMOTO #include "cachelib.h" 3106a99fe3SHajimu UMEMOTO #include "config.h" 3206a99fe3SHajimu UMEMOTO #include "protocol.h" 3306a99fe3SHajimu UMEMOTO 3406a99fe3SHajimu UMEMOTO struct query_state; 3506a99fe3SHajimu UMEMOTO struct configuration; 3606a99fe3SHajimu UMEMOTO struct configuration_entry; 3706a99fe3SHajimu UMEMOTO 3806a99fe3SHajimu UMEMOTO typedef int (*query_process_func)(struct query_state *); 3906a99fe3SHajimu UMEMOTO typedef void (*query_destroy_func)(struct query_state *); 4006a99fe3SHajimu UMEMOTO typedef ssize_t (*query_read_func)(struct query_state *, void *, size_t); 41d2432adbSDag-Erling Smørgrav typedef ssize_t (*query_write_func)(struct query_state *, const void *, size_t); 4206a99fe3SHajimu UMEMOTO 4306a99fe3SHajimu UMEMOTO /* 4406a99fe3SHajimu UMEMOTO * The query state structure contains the information to process all types of 4506a99fe3SHajimu UMEMOTO * requests and to send all types of responses. 4606a99fe3SHajimu UMEMOTO */ 4706a99fe3SHajimu UMEMOTO struct query_state { 4806a99fe3SHajimu UMEMOTO struct timeval creation_time; 4906a99fe3SHajimu UMEMOTO struct timeval timeout; 5006a99fe3SHajimu UMEMOTO 5106a99fe3SHajimu UMEMOTO struct comm_element request; 5206a99fe3SHajimu UMEMOTO struct comm_element response; 5306a99fe3SHajimu UMEMOTO struct configuration_entry *config_entry; 5406a99fe3SHajimu UMEMOTO void *mdata; 5506a99fe3SHajimu UMEMOTO 5606a99fe3SHajimu UMEMOTO query_process_func process_func; /* called on each event */ 5706a99fe3SHajimu UMEMOTO query_destroy_func destroy_func; /* called on destroy */ 5806a99fe3SHajimu UMEMOTO 5906a99fe3SHajimu UMEMOTO /* 6006a99fe3SHajimu UMEMOTO * By substituting these functions we can opaquely send and received 6106a99fe3SHajimu UMEMOTO * very large buffers 6206a99fe3SHajimu UMEMOTO */ 6306a99fe3SHajimu UMEMOTO query_write_func write_func; /* data write function */ 6406a99fe3SHajimu UMEMOTO query_read_func read_func; /* data read function */ 6506a99fe3SHajimu UMEMOTO 6606a99fe3SHajimu UMEMOTO char *eid_str; /* the user-identifying string (euid_egid_) */ 6706a99fe3SHajimu UMEMOTO size_t eid_str_length; 6806a99fe3SHajimu UMEMOTO 6906a99fe3SHajimu UMEMOTO uid_t euid; /* euid of the caller, received via getpeereid */ 7006a99fe3SHajimu UMEMOTO uid_t uid; /* uid of the caller, received via credentials */ 7106a99fe3SHajimu UMEMOTO gid_t egid; /* egid of the caller, received via getpeereid */ 7206a99fe3SHajimu UMEMOTO gid_t gid; /* gid of the caller received via credentials */ 7306a99fe3SHajimu UMEMOTO 7406a99fe3SHajimu UMEMOTO size_t io_buffer_size; 7506a99fe3SHajimu UMEMOTO size_t io_buffer_watermark; 7606a99fe3SHajimu UMEMOTO size_t kevent_watermark; /* bytes to be sent/received */ 7706a99fe3SHajimu UMEMOTO int sockfd; /* the unix socket to read/write */ 7806a99fe3SHajimu UMEMOTO int kevent_filter; /* EVFILT_READ or EVFILT_WRITE */ 7906a99fe3SHajimu UMEMOTO int socket_failed; /* set to 1 if the socket doesn't work correctly */ 8006a99fe3SHajimu UMEMOTO 8106a99fe3SHajimu UMEMOTO /* 8206a99fe3SHajimu UMEMOTO * These fields are used to opaquely proceed sending/receiving of 8306a99fe3SHajimu UMEMOTO * the large buffers 8406a99fe3SHajimu UMEMOTO */ 8506a99fe3SHajimu UMEMOTO char *io_buffer; 8606a99fe3SHajimu UMEMOTO char *io_buffer_p; 8706a99fe3SHajimu UMEMOTO int io_buffer_filter; 8806a99fe3SHajimu UMEMOTO int use_alternate_io; 8906a99fe3SHajimu UMEMOTO }; 9006a99fe3SHajimu UMEMOTO 91d2432adbSDag-Erling Smørgrav int check_query_eids(struct query_state *); 9206a99fe3SHajimu UMEMOTO 93d2432adbSDag-Erling Smørgrav ssize_t query_io_buffer_read(struct query_state *, void *, size_t); 94d2432adbSDag-Erling Smørgrav ssize_t query_io_buffer_write(struct query_state *, const void *, size_t); 9506a99fe3SHajimu UMEMOTO 96d2432adbSDag-Erling Smørgrav ssize_t query_socket_read(struct query_state *, void *, size_t); 97d2432adbSDag-Erling Smørgrav ssize_t query_socket_write(struct query_state *, const void *, size_t); 9806a99fe3SHajimu UMEMOTO 99d2432adbSDag-Erling Smørgrav struct query_state *init_query_state(int, size_t, uid_t, gid_t); 100d2432adbSDag-Erling Smørgrav void destroy_query_state(struct query_state *); 10106a99fe3SHajimu UMEMOTO 10206a99fe3SHajimu UMEMOTO #endif 103