@@ -109,6 +109,10 @@ static conf_option conf_server_options[] = {
109
109
CONF_FIELD_TYPE_SDS , 0 ,
110
110
conf_set_password , conf_get_sds ,
111
111
offsetof(conf_server , adminpass ) },
112
+ { (char * )CONFIG_SOPN_COMMANDSNAP ,
113
+ CONF_FIELD_TYPE_ARRAYSDS , 1 ,
114
+ conf_set_commands_need_adminpass , conf_get_array_sds ,
115
+ offsetof(conf_server , commands_need_adminpass ) },
112
116
{ NULL , NULL , 0 }
113
117
};
114
118
@@ -579,6 +583,53 @@ conf_set_array_sds(void *obj, conf_option *opt, void *data)
579
583
return VR_OK ;
580
584
}
581
585
586
+ int
587
+ conf_set_commands_need_adminpass (void * obj , conf_option * opt , void * data )
588
+ {
589
+ uint8_t * p ;
590
+ uint32_t j ;
591
+ conf_value * * cv_sub , * cv = data ;
592
+ struct array * gt ;
593
+ sds * str ;
594
+
595
+ if (cv -> type != CONF_VALUE_TYPE_STRING &&
596
+ cv -> type != CONF_VALUE_TYPE_ARRAY ){
597
+ log_error ("conf pool %s in the conf file is not a string or array" ,
598
+ opt -> name );
599
+ return VR_ERROR ;
600
+ } else if (cv -> type == CONF_VALUE_TYPE_ARRAY ) {
601
+ cv_sub = array_get (cv -> value , j );
602
+ if ((* cv_sub )-> type != CONF_VALUE_TYPE_STRING ) {
603
+ log_error ("conf pool %s in the conf file is not a string array" ,
604
+ opt -> name );
605
+ return VR_ERROR ;
606
+ }
607
+ }
608
+
609
+ CONF_WLOCK ();
610
+ p = obj ;
611
+ gt = (struct array * )(p + opt -> offset );
612
+
613
+ while (array_n (gt ) > 0 ) {
614
+ str = array_pop (gt );
615
+ sdsfree (* str );
616
+ }
617
+
618
+ if (cv -> type == CONF_VALUE_TYPE_STRING ) {
619
+ str = array_push (gt );
620
+ * str = sdsdup (cv -> value );
621
+ } else if (cv -> type == CONF_VALUE_TYPE_ARRAY ) {
622
+ for (j = 0 ; j < array_n (cv -> value ); j ++ ) {
623
+ cv_sub = array_get (cv -> value , j );
624
+ str = array_push (gt );
625
+ * str = sdsdup ((* cv_sub )-> value );
626
+ }
627
+ }
628
+ conf -> version ++ ;
629
+ CONF_UNLOCK ();
630
+ return VR_OK ;
631
+ }
632
+
582
633
int
583
634
conf_get_array_sds (void * obj , conf_option * opt , void * data )
584
635
{
@@ -724,6 +775,7 @@ static int conf_server_init(conf_server *cs)
724
775
cs -> requirepass = CONF_UNSET_PTR ;
725
776
cs -> adminpass = CONF_UNSET_PTR ;
726
777
cs -> dir = CONF_UNSET_PTR ;
778
+ array_init (& cs -> commands_need_adminpass ,1 ,sizeof (sds ));
727
779
728
780
return VR_OK ;
729
781
}
@@ -768,6 +820,11 @@ static int conf_server_set_default(conf_server *cs)
768
820
}
769
821
cs -> dir = sdsnew (CONFIG_DEFAULT_DATA_DIR );
770
822
823
+ while (array_n (& cs -> commands_need_adminpass ) > 0 ) {
824
+ str = array_pop (& cs -> commands_need_adminpass );
825
+ sdsfree (* str );
826
+ }
827
+
771
828
return VR_OK ;
772
829
}
773
830
@@ -809,6 +866,12 @@ static void conf_server_deinit(conf_server *cs)
809
866
sdsfree (cs -> adminpass );
810
867
cs -> adminpass = CONF_UNSET_PTR ;
811
868
}
869
+
870
+ while (array_n (& cs -> commands_need_adminpass ) > 0 ) {
871
+ str = array_pop (& cs -> commands_need_adminpass );
872
+ sdsfree (* str );
873
+ }
874
+ array_deinit (& cs -> commands_need_adminpass );
812
875
}
813
876
814
877
int
@@ -1497,9 +1560,7 @@ static void addReplyConfOption(client *c,conf_option *cop)
1497
1560
1498
1561
static void configGetCommand (client * c ) {
1499
1562
robj * o = c -> argv [2 ];
1500
- void * replylen = addDeferredMultiBulkLength (c );
1501
1563
char * pattern = o -> ptr ;
1502
- int matches = 0 ;
1503
1564
conf_option * cop ;
1504
1565
serverAssertWithInfo (c ,o ,sdsEncodedObject (o ));
1505
1566
@@ -1508,12 +1569,14 @@ static void configGetCommand(client *c) {
1508
1569
/* Don't show adminpass if user has no right. */
1509
1570
if (!strcmp (cop -> name ,CONFIG_SOPN_ADMINPASS ) &&
1510
1571
c -> vel -> cc .adminpass && c -> authenticated < 2 ) {
1511
- /* Nothing to show */
1572
+ addReply ( c , shared . noadminerr );
1512
1573
} else {
1574
+ addReplyMultiBulkLen (c ,2 );
1513
1575
addReplyConfOption (c ,cop );
1514
- matches ++ ;
1515
1576
}
1516
1577
} else {
1578
+ int matches = 0 ;
1579
+ void * replylen = addDeferredMultiBulkLength (c );
1517
1580
for (cop = conf_server_options ; cop && cop -> name ; cop ++ ) {
1518
1581
if (stringmatch (pattern ,cop -> name ,1 )) {
1519
1582
/* Don't show adminpass if user has no right. */
@@ -1525,8 +1588,8 @@ static void configGetCommand(client *c) {
1525
1588
matches ++ ;
1526
1589
}
1527
1590
}
1591
+ setDeferredMultiBulkLength (c ,replylen ,matches * 2 );
1528
1592
}
1529
- setDeferredMultiBulkLength (c ,replylen ,matches * 2 );
1530
1593
}
1531
1594
1532
1595
/*-----------------------------------------------------------------------------
@@ -1952,6 +2015,32 @@ static void rewriteConfigBindOption(struct rewriteConfigState *state) {
1952
2015
rewriteConfigRewriteLine (state ,option ,line ,force );
1953
2016
}
1954
2017
2018
+ /* Rewrite the save option. */
2019
+ void rewriteConfigCommandsNAPOption (struct rewriteConfigState * state ) {
2020
+ struct array values ;
2021
+ sds * value , line ;
2022
+ int force = 1 ;
2023
+ char * option = CONFIG_SOPN_COMMANDSNAP ;
2024
+
2025
+ array_init (& values ,1 ,sizeof (sds ));
2026
+ conf_server_get (option ,& values );
2027
+ /* Nothing to rewrite if we don't have commands that need adminpass. */
2028
+ if (array_n (& values ) == 0 ) {
2029
+ array_deinit (& values );
2030
+ rewriteConfigMarkAsProcessed (state ,option );
2031
+ return ;
2032
+ }
2033
+
2034
+ while (array_n (& values ) > 0 ) {
2035
+ value = array_pop (& values );
2036
+ line = sdscatprintf (sdsempty (),"%s %s" ,option ,* value );
2037
+ rewriteConfigRewriteLine (state ,option ,line ,force );
2038
+ sdsfree (* value );
2039
+ }
2040
+ array_deinit (& values );
2041
+ rewriteConfigMarkAsProcessed (state ,option );
2042
+ }
2043
+
1955
2044
/* Rewrite the configuration file at "path".
1956
2045
* If the configuration file already exists, we try at best to retain comments
1957
2046
* and overall structure.
@@ -1989,6 +2078,7 @@ static int rewriteConfig(char *path) {
1989
2078
rewriteConfigIntOption (state ,CONFIG_SOPN_MAXCLIENTS ,CONFIG_DEFAULT_MAX_CLIENTS );
1990
2079
rewriteConfigSdsOption (state ,CONFIG_SOPN_REQUIREPASS ,NULL );
1991
2080
rewriteConfigSdsOption (state ,CONFIG_SOPN_ADMINPASS ,NULL );
2081
+ rewriteConfigCommandsNAPOption (state );
1992
2082
1993
2083
/* Step 3: remove all the orphaned lines in the old file, that is, lines
1994
2084
* that were used by a config option and are no longer used, like in case
0 commit comments