2014-07-23 09:58:45 +02:00
/*
Unix SMB / CIFS implementation .
Main metadata server / Spotlight routines
Copyright ( C ) Ralph Boehme 2012 - 2014
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2014-07-31 17:07:28 +02:00
# ifndef _MDSSVC_H
# define _MDSSVC_H
# include "dalloc.h"
# include "marshalling.h"
2015-03-26 22:39:21 +01:00
# include "lib/util/dlinklist.h"
# include "librpc/gen_ndr/mdssvc.h"
/*
* glib uses TRUE and FALSE which was redefined by " includes.h " to be
* unusable , undefine so glib can establish its own working
* replacement .
*/
# undef TRUE
# undef FALSE
# define MAX_SL_FRAGMENT_SIZE 0xFFFFF
# define MAX_SL_RESULTS 100
# define MAX_SL_RUNTIME 30
# define MDS_TRACKER_ASYNC_TIMEOUT_MS 250
2019-08-07 11:59:39 +02:00
# define SLQ_DEBUG(lvl, _slq, state) do { if (CHECK_DEBUGLVL(lvl)) { \
const struct sl_query * __slq = _slq ; \
struct timeval_buf start_buf ; \
const char * start ; \
struct timeval_buf last_used_buf ; \
const char * last_used ; \
struct timeval_buf expire_buf ; \
const char * expire ; \
start = timeval_str_buf ( & __slq - > start_time , false , \
true , & start_buf ) ; \
last_used = timeval_str_buf ( & __slq - > last_used , false , \
true , & last_used_buf ) ; \
expire = timeval_str_buf ( & __slq - > expire_time , false , \
true , & expire_buf ) ; \
DEBUG ( lvl , ( " %s slq[0x%jx,0x%jx], start: %s, last_used: %s, " \
" expires: %s, query: '%s' \n " , state , \
( uintmax_t ) __slq - > ctx1 , ( uintmax_t ) __slq - > ctx2 , \
start , last_used , expire , __slq - > query_string ) ) ; \
} } while ( 0 )
2015-03-26 22:39:21 +01:00
/******************************************************************************
* Some helper stuff dealing with queries
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* query state */
typedef enum {
SLQ_STATE_NEW , /* Query received from client */
SLQ_STATE_RUNNING , /* Query dispatched to Tracker */
SLQ_STATE_RESULTS , /* Async Tracker query read */
2023-07-17 15:01:21 +02:00
SLQ_STATE_FULL , /* the max amount of result has been queued */
2015-03-26 22:39:21 +01:00
SLQ_STATE_DONE , /* Got all results from Tracker */
SLQ_STATE_END , /* Query results returned to client */
2023-07-17 15:01:21 +02:00
SLQ_STATE_ERROR /* an error happened somewhere */
2015-03-26 22:39:21 +01:00
} slq_state_t ;
/* query structure */
struct sl_query {
struct sl_query * prev , * next ; /* list pointers */
struct mds_ctx * mds_ctx ; /* context handle */
2019-03-14 07:38:20 +01:00
void * backend_private ; /* search backend private data */
2015-03-26 22:39:21 +01:00
slq_state_t state ; /* query state */
struct timeval start_time ; /* Query start time */
struct timeval last_used ; /* Time of last result fetch */
struct timeval expire_time ; /* Query expiration time */
struct tevent_timer * te ; /* query timeout */
uint64_t ctx1 ; /* client context 1 */
uint64_t ctx2 ; /* client context 2 */
sl_array_t * reqinfo ; /* array with requested metadata */
2019-04-09 11:19:43 +02:00
char * query_string ; /* the Spotlight query string */
2015-03-26 22:39:21 +01:00
uint64_t * cnids ; /* restrict query to these CNIDs */
size_t cnids_num ; /* Size of slq_cnids array */
const char * path_scope ; /* path to directory to search */
struct sl_rslts * query_results ; /* query results */
TALLOC_CTX * entries_ctx ; /* talloc parent of the search results */
} ;
struct sl_rslts {
int num_results ;
sl_cnids_t * cnids ;
sl_array_t * fm_array ;
} ;
struct sl_inode_path_map {
struct mds_ctx * mds_ctx ;
uint64_t ino ;
char * path ;
2023-06-06 15:17:26 +02:00
struct stat_ex st ;
2015-03-26 22:39:21 +01:00
} ;
2016-01-27 13:23:51 +01:00
/* Per process state */
struct mdssvc_ctx {
struct tevent_context * ev_ctx ;
2019-03-14 07:38:20 +01:00
void * backend_private ;
2016-01-27 13:23:51 +01:00
} ;
/* Per tree connect state */
2015-03-26 22:39:21 +01:00
struct mds_ctx {
2019-05-06 15:03:02 +02:00
struct mdssvc_backend * backend ;
2016-01-27 13:23:51 +01:00
struct mdssvc_ctx * mdssvc_ctx ;
2019-03-14 07:38:20 +01:00
void * backend_private ;
2019-03-11 18:11:04 +01:00
struct auth_session_info * pipe_session_info ;
2015-03-26 22:39:21 +01:00
struct dom_sid sid ;
uid_t uid ;
2019-04-09 11:19:43 +02:00
smb_iconv_t ic_nfc_to_nfd ;
smb_iconv_t ic_nfd_to_nfc ;
2019-04-12 12:15:56 +02:00
int snum ;
const char * sharename ;
2015-03-26 22:39:21 +01:00
const char * spath ;
2023-06-05 18:02:20 +02:00
size_t spath_len ;
2021-05-10 12:10:08 +02:00
struct connection_struct * conn ;
2015-03-26 22:39:21 +01:00
struct sl_query * query_list ; /* list of active queries */
struct db_context * ino_path_map ; /* dbwrap rbt for storing inode->path mappings */
} ;
2014-07-31 17:07:28 +02:00
2019-03-14 07:38:20 +01:00
struct mdssvc_backend {
bool ( * init ) ( struct mdssvc_ctx * mdssvc_ctx ) ;
bool ( * connect ) ( struct mds_ctx * mds_ctx ) ;
bool ( * search_map ) ( struct sl_query * slq ) ;
bool ( * search_start ) ( struct sl_query * slq ) ;
bool ( * search_cont ) ( struct sl_query * slq ) ;
bool ( * shutdown ) ( struct mdssvc_ctx * mdssvc_ctx ) ;
} ;
2014-07-31 17:07:28 +02:00
/******************************************************************************
* Function declarations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* mdssvc . c
*/
2015-03-26 22:39:21 +01:00
extern bool mds_init ( struct messaging_context * msg_ctx ) ;
extern bool mds_shutdown ( void ) ;
2022-05-25 17:26:29 +02:00
NTSTATUS mds_init_ctx ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct messaging_context * msg_ctx ,
struct auth_session_info * session_info ,
int snum ,
const char * sharename ,
const char * path ,
struct mds_ctx * * _mds_ctx ) ;
2023-06-19 18:16:57 +02:00
extern bool mds_dispatch ( struct mds_ctx * mds_ctx ,
2015-03-26 22:39:21 +01:00
struct mdssvc_blob * request_blob ,
2023-06-19 18:16:57 +02:00
struct mdssvc_blob * response_blob ,
size_t max_fragment_size ) ;
2019-03-14 07:38:20 +01:00
bool mds_add_result ( struct sl_query * slq , const char * path ) ;
2014-07-31 17:07:28 +02:00
# endif /* _MDSSVC_H */