Skip to content

Commit c912721

Browse files
authored
Merge cc8e834 into 251fb63
2 parents 251fb63 + cc8e834 commit c912721

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3324
-205
lines changed

api/libsphinxclient/sphinxclient.c

Lines changed: 200 additions & 23 deletions
Large diffs are not rendered by default.

api/libsphinxclient/sphinxclient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ sphinx_keyword_info * sphinx_build_keywords ( sphinx_client * client, const c
255255
char ** sphinx_status ( sphinx_client * client, int * num_rows, int * num_cols );
256256
char ** sphinx_status_extended ( sphinx_client * client, int * num_rows, int * num_cols, int local );
257257
void sphinx_status_destroy ( char ** status, int num_rows, int num_cols );
258+
sphinx_bool sphinx_set_user ( sphinx_client * client, const char * user, const char * password );
258259

259260
/////////////////////////////////////////////////////////////////////////////
260261

api/libsphinxclient/test.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ void test_excerpt ( sphinx_client * client )
155155
g_failed += ( res==NULL );
156156
if ( !g_smoke )
157157
die ( "query failed: %s", sphinx_error(client) );
158+
} else
159+
{
160+
for ( i=0; i<ndocs; i++ )
161+
printf ( "n=%d, res=%s\n", 1+i, res[i] );
158162
}
159-
160-
for ( i=0; i<ndocs; i++ )
161-
printf ( "n=%d, res=%s\n", 1+i, res[i] );
162163
}
163164

164165

@@ -205,11 +206,18 @@ void test_excerpt_spz ( sphinx_client * client )
205206

206207
res = sphinx_build_excerpts ( client, ndocs, (const char **)docs, index, words, &opts );
207208
if ( !res )
208-
die ( "query failed: %s", sphinx_error(client) );
209+
{
210+
if ( !g_smoke )
211+
die ( "query failed: %s", sphinx_error(client) );
212+
else
213+
printf ( "query failed: %s", sphinx_error(client) );
209214

210-
for ( i=0; i<ndocs; i++ )
211-
printf ( "n=%d, res=%s\n", 1+i, res[i] );
212-
printf ( "\n" );
215+
} else
216+
{
217+
for ( i=0; i<ndocs; i++ )
218+
printf ( "n=%d, res=%s\n", 1+i, res[i] );
219+
printf ( "\n" );
220+
}
213221
}
214222
}
215223

@@ -426,17 +434,32 @@ void title ( const char * name )
426434

427435
int main ( int argc, char ** argv )
428436
{
429-
int i, port = 0;
437+
int i, port = 9312;
430438
sphinx_client * client;
431439
// sphinx_uint64_t override_docid = 2;
432440
// unsigned int override_value = 2000;
441+
const char * user = NULL;
442+
const char * password = NULL;
433443

434444
for ( i=1; i<argc; i++ )
435445
{
436446
if ( strcmp ( argv[i], "--smoke" )==0 )
437447
g_smoke = SPH_TRUE;
438448
else if ( strcmp ( argv[i], "--port" )==0 && i+1<argc )
449+
{
439450
port = (int)strtoul ( argv[i+1], NULL, 10 );
451+
i++;
452+
}
453+
else if ( strcmp ( argv[i], "--user" )==0 && i+1<argc )
454+
{
455+
user = argv[i+1];
456+
i++;
457+
}
458+
else if ( strcmp ( argv[i], "--password" )==0 && i+1<argc )
459+
{
460+
password = argv[i+1];
461+
i++;
462+
}
440463
}
441464

442465
net_init ();
@@ -447,6 +470,8 @@ int main ( int argc, char ** argv )
447470

448471
if ( port )
449472
sphinx_set_server ( client, "127.0.0.1", port );
473+
if ( user )
474+
sphinx_set_user ( client, user, password );
450475

451476
sphinx_set_match_mode ( client, SPH_MATCH_EXTENDED2 );
452477
sphinx_set_sort_mode ( client, SPH_SORT_RELEVANCE, NULL );
@@ -495,6 +520,8 @@ int main ( int argc, char ** argv )
495520
test_query ( client, "is", "test1" );
496521

497522
sphinx_cleanup ( client );
523+
if ( user )
524+
sphinx_set_user ( client, user, password );
498525

499526
// group_by (attr; mva) + filter + post update
500527
title ( "group_by (attr; mva) + filter + post update" );

api/sphinxapi.php

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
define ( "SPH_UPDATE_STRING", 2 );
122122
define ( "SPH_UPDATE_JSON", 3 );
123123

124+
/// known auth types
125+
define ( "AUTH_NO", 1 );
126+
define ( "AUTH_SHA1", 2 );
127+
define ( "AUTH_SHA256", 3 );
128+
129+
124130
// important properties of PHP's integers:
125131
// - always signed (one bit short of PHP_INT_SIZE)
126132
// - conversion from string to int is saturated
@@ -459,6 +465,9 @@ class SphinxClient
459465
var $_token_filter_library; ///< token_filter plugin library name
460466
var $_token_filter_name; ///< token_filter plugin name
461467
var $_token_filter_opts; ///< token_filter plugin options
468+
469+
var $user; ///< user name
470+
var $user_token; ///< user hashed password
462471

463472
var $_error; ///< last error message
464473
var $_warning; ///< last warning message
@@ -528,6 +537,9 @@ function __construct ()
528537
$this->_mbenc = "";
529538
$this->_arrayresult = false;
530539
$this->_timeout = 0;
540+
541+
$this->user = '';
542+
$this->user_token = '';
531543
}
532544

533545
function __destruct()
@@ -584,8 +596,18 @@ function SetConnectTimeout ( $timeout )
584596
}
585597

586598

587-
function _Send ( $handle, $data, $length )
599+
function _Send ( $handle, $data, $length, $add_auth )
588600
{
601+
if ( $add_auth )
602+
{
603+
// auth data head
604+
$auth_head = $this->GetUserData();
605+
$length += strlen ( $auth_head );
606+
607+
$auth_head .= $data;
608+
$data = $auth_head;
609+
}
610+
589611
if ( feof($handle) || fwrite ( $handle, $data, $length ) !== $length )
590612
{
591613
$this->_error = 'connection unexpectedly closed (timed out?)';
@@ -666,7 +688,7 @@ function _Connect ()
666688
// this is a subtle part. we must do it before (!) reading back from searchd.
667689
// because otherwise under some conditions (reported on FreeBSD for instance)
668690
// TCP stack could throttle write-write-read pattern because of Nagle.
669-
if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) )
691+
if ( !$this->_Send ( $fp, pack ( "N", 2 ), 4, false ) )
670692
{
671693
fclose ( $fp );
672694
$this->_error = "failed to send client protocol version";
@@ -1294,7 +1316,7 @@ function RunQueries ()
12941316
$len = 8+strlen($req);
12951317
$req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header
12961318

1297-
if ( !( $this->_Send ( $fp, $req, $len+8 ) ) ||
1319+
if ( !( $this->_Send ( $fp, $req, $len+8, true ) ) ||
12981320
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) )
12991321
{
13001322
$this->_MBPop ();
@@ -1577,7 +1599,7 @@ function BuildExcerpts ( $docs, $index, $words, $opts=array() )
15771599

15781600
$len = strlen($req);
15791601
$req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header
1580-
if ( !( $this->_Send ( $fp, $req, $len+8 ) ) ||
1602+
if ( !( $this->_Send ( $fp, $req, $len+8, true ) ) ||
15811603
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) )
15821604
{
15831605
$this->_MBPop ();
@@ -1647,7 +1669,7 @@ function BuildKeywords ( $query, $index, $hits )
16471669

16481670
$len = strlen($req);
16491671
$req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header
1650-
if ( !( $this->_Send ( $fp, $req, $len+8 ) ) ||
1672+
if ( !( $this->_Send ( $fp, $req, $len+8, true ) ) ||
16511673
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) )
16521674
{
16531675
$this->_MBPop ();
@@ -1781,7 +1803,7 @@ function UpdateAttributes ( $index, $attrs, $values, $type=SPH_UPDATE_INT, $igno
17811803

17821804
$len = strlen($req);
17831805
$req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header
1784-
if ( !$this->_Send ( $fp, $req, $len+8 ) )
1806+
if ( !$this->_Send ( $fp, $req, $len+8, true ) )
17851807
{
17861808
$this->_MBPop ();
17871809
return -1;
@@ -1815,7 +1837,7 @@ function Open()
18151837

18161838
// command, command version = 0, body length = 4, body = 1
18171839
$req = pack ( "nnNN", SEARCHD_COMMAND_PERSIST, 0, 4, 1 );
1818-
if ( !$this->_Send ( $fp, $req, 12 ) )
1840+
if ( !$this->_Send ( $fp, $req, 12, true ) )
18191841
return false;
18201842

18211843
$this->_socket = $fp;
@@ -1852,7 +1874,7 @@ function Status ($session=false)
18521874
}
18531875

18541876
$req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, $session?0:1 ); // len=4, body=1
1855-
if ( !( $this->_Send ( $fp, $req, 12 ) ) ||
1877+
if ( !( $this->_Send ( $fp, $req, 12, true ) ) ||
18561878
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) )
18571879
{
18581880
$this->_MBPop ();
@@ -1888,7 +1910,7 @@ function FlushAttributes ()
18881910
}
18891911

18901912
$req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0
1891-
if ( !( $this->_Send ( $fp, $req, 8 ) ) ||
1913+
if ( !( $this->_Send ( $fp, $req, 8, true ) ) ||
18921914
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) )
18931915
{
18941916
$this->_MBPop ();
@@ -1904,6 +1926,35 @@ function FlushAttributes ()
19041926
$this->_MBPop ();
19051927
return $tag;
19061928
}
1929+
1930+
//////////////////////////////////////////////////////////////////////////
1931+
// user
1932+
//////////////////////////////////////////////////////////////////////////
1933+
1934+
function SetUser ($user, $password)
1935+
{
1936+
$this->user = $user;
1937+
1938+
$password_hash = hash ( "sha256", $password, true );
1939+
$pwd_hash = hash ( "sha256", $user . $password_hash, true );
1940+
$this->user_token = $pwd_hash;
1941+
}
1942+
1943+
function GetUserData ()
1944+
{
1945+
$data = '';
1946+
if ( $this->user=='' )
1947+
{
1948+
$data .= pack ( "C", AUTH_NO );
1949+
} else
1950+
{
1951+
$data .= pack ( "C", AUTH_SHA256 );
1952+
$data .= $this->user_token;
1953+
}
1954+
1955+
return $data;
1956+
}
1957+
19071958
}
19081959

19091960
//

manual/References.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ spelldump [options] <dictionary> <affix> [result] [locale-name]
604604
A comprehensive alphabetical list of keywords currently reserved in Manticore SQL syntax (thus, they cannot be used as identifiers).
605605
606606
```
607-
AND, AS, BY, COLUMNARSCAN, DISTINCT, DIV, DOCIDINDEX, EXPLAIN, FACET, FALSE, FORCE, FROM, IGNORE, IN, INDEXES, INNER, IS, JOIN, KNN, LEFT, LIMIT, MOD, NOT, NO_COLUMNARSCAN, NO_DOCIDINDEX, NO_SECONDARYINDEX, NULL, OFFSET, ON, OR, ORDER, RELOAD, SECONDARYINDEX, SELECT, SYSFILTERS, TRUE
607+
AND, AS, BY, COLUMNARSCAN, DISTINCT, DIV, DOCIDINDEX, EXPLAIN, FACET, FALSE, FORCE, FROM, IGNORE, IN, INDEXES, INNER, IS, JOIN, KNN, LEFT, LIMIT, MOD, NOT, NO_COLUMNARSCAN, NO_DOCIDINDEX, NO_SECONDARYINDEX, NULL, OFFSET, ON, OR, ORDER, RELOAD, SECONDARYINDEX, SELECT, SYSFILTERS, TOKEN, TRUE
608608
```
609609
610610
## Documentation for old Manticore versions

src/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ set ( SEARCHD_H searchdaemon.h searchdconfig.h searchdddl.h searchdexpr.h search
174174
compressed_zlib_mysql.h sphinxql_debug.h stackmock.h searchdssl.h digest_sha1.h
175175
client_session.h compressed_zstd_mysql.h docs_collector.h index_rotator.h config_reloader.h searchdhttp.h timeout_queue.h
176176
netpoll.h pollable_event.h netfetch.h searchdbuddy.h sphinxql_second.h sphinxql_extra.h sphinxjsonquery.h
177-
frontendschema.h debug_cmds.h dynamic_idx.h sphinxexcerpt.h)
177+
frontendschema.h debug_cmds.h dynamic_idx.h sphinxexcerpt.h
178+
auth/auth.h auth/auth_common.h auth/auth_proto_http.h auth/auth_proto_mysql.h auth/auth_proto_api.h digest_sha256.h auth/auth_perms.h)
178179

179180

180181
# add the extra targets in the case we want on-the-fly grammar compiler
@@ -255,11 +256,15 @@ add_library ( lsearchd OBJECT searchdha.cpp http/http_parser.c searchdhttp.cpp
255256
netreceive_http.cpp netreceive_ql.cpp query_status.cpp
256257
sphinxql_debug.cpp sphinxql_second.cpp stackmock.cpp docs_collector.cpp index_rotator.cpp config_reloader.cpp netpoll.cpp
257258
pollable_event.cpp netfetch.cpp searchdbuddy.cpp searchdhttpcompat.cpp sphinxql_extra.cpp searchdreplication.cpp sphinxjsonquery.cpp
258-
frontendschema.cpp compressed_http.cpp debug_cmds.cpp jsonqueryfilter.cpp dynamic_idx.cpp sphinxexcerpt.cpp searchdexpr.cpp)
259+
frontendschema.cpp compressed_http.cpp debug_cmds.cpp jsonqueryfilter.cpp dynamic_idx.cpp sphinxexcerpt.cpp searchdexpr.cpp
260+
auth/auth.cpp auth/auth_common.cpp auth/auth_proto_http.cpp auth/auth_proto_mysql.cpp auth/auth_proto_api.cpp auth/auth_perms.cpp)
261+
259262
target_sources ( lsearchd PUBLIC ${SEARCHD_SRCS_TESTABLE} ${SEARCHD_H} ${SEARCHD_BISON} ${SEARCHD_FLEX} )
260263
add_library ( digest_sha1 digest_sha1.cpp )
264+
add_library ( digest_sha256 digest_sha256.cpp )
261265
target_link_libraries ( digest_sha1 PRIVATE lextra )
262-
target_link_libraries ( lsearchd PUBLIC digest_sha1 lextra nlohmann_json::nlohmann_json )
266+
target_link_libraries ( digest_sha256 PRIVATE lextra )
267+
target_link_libraries ( lsearchd PUBLIC digest_sha1 digest_sha256 lextra nlohmann_json::nlohmann_json )
263268
target_link_libraries ( lsearchd INTERFACE Boost::filesystem )
264269

265270
function (stackmock processors compiler versions config values)
@@ -332,9 +337,12 @@ if (WITH_SSL)
332337
target_link_libraries ( searchd_ssl PRIVATE OpenSSL::Crypto )
333338
target_link_libraries ( digest_sha1 PRIVATE OpenSSL::SSL )
334339
target_link_libraries ( digest_sha1 PRIVATE OpenSSL::Crypto )
340+
target_link_libraries ( digest_sha256 PRIVATE OpenSSL::SSL )
341+
target_link_libraries ( digest_sha256 PRIVATE OpenSSL::Crypto )
335342
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
336343
target_link_options ( searchd_ssl INTERFACE $<${ONLYGNUCLANGC_CXX}:-Wl,--exclude-libs,libssl.a,--exclude-libs,libcrypto.a> )
337344
target_link_options ( digest_sha1 INTERFACE $<${ONLYGNUCLANGC_CXX}:-Wl,--exclude-libs,libssl.a,--exclude-libs,libcrypto.a> )
345+
target_link_options ( digest_sha256 INTERFACE $<${ONLYGNUCLANGC_CXX}:-Wl,--exclude-libs,libssl.a,--exclude-libs,libcrypto.a> )
338346
endif()
339347
target_compile_options ( searchd_ssl PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-deprecated-declarations>" )
340348
include ( CheckFunctionExists )

0 commit comments

Comments
 (0)