summaryrefslogtreecommitdiff
path: root/src/mongo/db/server_options_server_helpers.cpp
blob: fb6191b341015a4c99984de75bedc698471133f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737

/**
 *    Copyright (C) 2018-present MongoDB, Inc.
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the Server Side Public License, version 1,
 *    as published by MongoDB, Inc.
 *
 *    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
 *    Server Side Public License for more details.
 *
 *    You should have received a copy of the Server Side Public License
 *    along with this program. If not, see
 *    <http://www.mongodb.com/licensing/server-side-public-license>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the Server Side Public License in all respects for
 *    all of the code used other than as permitted herein. If you modify file(s)
 *    with this exception, you may extend this exception to your version of the
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 *    delete this exception statement from your version. If you delete this
 *    exception statement from all source files in the program, then also delete
 *    it in the license file.
 */

#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kControl

#include "mongo/db/server_options_server_helpers.h"

#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <ios>
#include <iostream>

#include "mongo/base/status.h"
#include "mongo/bson/util/builder.h"
#include "mongo/config.h"
#include "mongo/db/server_options.h"
#include "mongo/db/server_options_helpers.h"
#include "mongo/db/server_parameters.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/transport/message_compressor_registry.h"
#include "mongo/util/cmdline_utils/censor_cmdline.h"
#include "mongo/util/fail_point_service.h"
#include "mongo/util/log.h"
#include "mongo/util/map_util.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/net/sock.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/options_parser/options_parser.h"
#include "mongo/util/options_parser/startup_options.h"

using std::endl;
using std::string;

namespace mongo {

Status addGeneralServerOptions(moe::OptionSection* options) {
    auto baseResult = addBaseServerOptions(options);
    if (!baseResult.isOK()) {
        return baseResult;
    }

    StringBuilder maxConnInfoBuilder;
    std::stringstream unixSockPermsBuilder;

    maxConnInfoBuilder << "max number of simultaneous connections - " << DEFAULT_MAX_CONN
                       << " by default";
    unixSockPermsBuilder << "permissions to set on UNIX domain socket file - "
                         << "0" << std::oct << DEFAULT_UNIX_PERMS << " by default";

    options->addOptionChaining("help", "help,h", moe::Switch, "show this usage information")
        .setSources(moe::SourceAllLegacy);

    options->addOptionChaining("version", "version", moe::Switch, "show version information")
        .setSources(moe::SourceAllLegacy);

    options
        ->addOptionChaining(
            "config", "config,f", moe::String, "configuration file specifying additional options")
        .setSources(moe::SourceAllLegacy);

    options
        ->addOptionChaining("outputConfig",
                            "outputConfig",
                            moe::Switch,
                            "Display the resolved configuration and exit")
        .setSources(moe::SourceCommandLine)
        .hidden();

    options
        ->addOptionChaining("configExpand",
                            "configExpand",
                            moe::String,
                            "Process expansion directives in config file (none, exec, rest)")
        .setSources(moe::SourceCommandLine);

    options
        ->addOptionChaining(
            "configExpandTimeoutSecs",
            "configExpandTimeoutSecs",
            moe::Int,
            str::stream() << "Maximum number of seconds to wait for a single "
                             "configuration expansion to resolve (default: "
                          << durationCount<Seconds>(optionenvironment::kDefaultConfigExpandTimeout)
                          << " secs)")
        .setSources(moe::SourceCommandLine)
        .hidden();

    options->addOptionChaining(
        "net.bindIp",
        "bind_ip",
        moe::String,
        "comma separated list of ip addresses to listen on - localhost by default");

    options
        ->addOptionChaining("net.bindIpAll", "bind_ip_all", moe::Switch, "bind to all ip addresses")
        .canonicalize([](moe::Environment* env) {
            bool all = (*env)["net.bindIpAll"].as<bool>();
            auto status = env->remove("net.bindIpAll");
            if (!status.isOK()) {
                return status;
            }
            return all ? env->set("net.bindIp", moe::Value("*")) : Status::OK();
        });

    options->addOptionChaining(
        "net.ipv6", "ipv6", moe::Switch, "enable IPv6 support (disabled by default)");

    options
        ->addOptionChaining(
            "net.listenBacklog", "listenBacklog", moe::Int, "set socket listen backlog size")
        .setDefault(moe::Value(SOMAXCONN));

    options->addOptionChaining(
        "net.maxIncomingConnections", "maxConns", moe::Int, maxConnInfoBuilder.str().c_str());

    options
        ->addOptionChaining(
            "net.maxIncomingConnectionsOverride",
            "",
            moe::StringVector,
            "CIDR ranges that do not count towards the maxIncomingConnections limit")
        .hidden()
        .setSources(moe::SourceYAMLConfig);

    options
        ->addOptionChaining(
            "net.reservedAdminThreads",
            "",
            moe::Int,
            "number of worker threads to reserve for admin and internal connections")
        .hidden()
        .setSources(moe::SourceYAMLConfig);

    options
        ->addOptionChaining("net.transportLayer",
                            "transportLayer",
                            moe::String,
                            "sets the ingress transport layer implementation")
        .hidden()
        .setDefault(moe::Value("asio"));

    options
        ->addOptionChaining("net.serviceExecutor",
                            "serviceExecutor",
                            moe::String,
                            "sets the service executor implementation")
        .hidden()
        .setDefault(moe::Value("synchronous"));

#if MONGO_ENTERPRISE_VERSION
    options->addOptionChaining("security.redactClientLogData",
                               "redactClientLogData",
                               moe::Switch,
                               "Redact client data written to the diagnostics log");
#endif

    options->addOptionChaining("processManagement.pidFilePath",
                               "pidfilepath",
                               moe::String,
                               "full path to pidfile (if not set, no pidfile is created)");

    options->addOptionChaining("processManagement.timeZoneInfo",
                               "timeZoneInfo",
                               moe::String,
                               "full path to time zone info directory, e.g. /usr/share/zoneinfo");

    options
        ->addOptionChaining(
            "security.keyFile", "keyFile", moe::String, "private key for cluster authentication")
        .incompatibleWith("noauth");

    options->addOptionChaining("noauth", "noauth", moe::Switch, "run without security")
        .setSources(moe::SourceAllLegacy)
        .incompatibleWith("auth")
        .incompatibleWith("keyFile")
        .incompatibleWith("transitionToAuth")
        .incompatibleWith("clusterAuthMode");

    options
        ->addOptionChaining(
            "security.transitionToAuth",
            "transitionToAuth",
            moe::Switch,
            "For rolling access control upgrade. Attempt to authenticate over outgoing "
            "connections and proceed regardless of success. Accept incoming connections "
            "with or without authentication.")
        .incompatibleWith("noauth");

    options
        ->addOptionChaining("security.clusterAuthMode",
                            "clusterAuthMode",
                            moe::String,
                            "Authentication mode used for cluster authentication. Alternatives are "
                            "(keyFile|sendKeyFile|sendX509|x509)")
        .format("(:?keyFile)|(:?sendKeyFile)|(:?sendX509)|(:?x509)",
                "(keyFile/sendKeyFile/sendX509/x509)");

#ifndef _WIN32
    options
        ->addOptionChaining(
            "nounixsocket", "nounixsocket", moe::Switch, "disable listening on unix sockets")
        .setSources(moe::SourceAllLegacy);

    options
        ->addOptionChaining(
            "net.unixDomainSocket.enabled", "", moe::Bool, "disable listening on unix sockets")
        .setSources(moe::SourceYAMLConfig);

    options->addOptionChaining("net.unixDomainSocket.pathPrefix",
                               "unixSocketPrefix",
                               moe::String,
                               "alternative directory for UNIX domain sockets (defaults to /tmp)");

    options->addOptionChaining("net.unixDomainSocket.filePermissions",
                               "filePermissions",
                               moe::Int,
                               unixSockPermsBuilder.str());

    options->addOptionChaining(
        "processManagement.fork", "fork", moe::Switch, "fork server process");

#endif

    options
        ->addOptionChaining("objcheck",
                            "objcheck",
                            moe::Switch,
                            "inspect client data for validity on receipt (DEFAULT)")
        .hidden()
        .setSources(moe::SourceAllLegacy)
        .incompatibleWith("noobjcheck");

    options
        ->addOptionChaining("noobjcheck",
                            "noobjcheck",
                            moe::Switch,
                            "do NOT inspect client data for validity on receipt")
        .hidden()
        .setSources(moe::SourceAllLegacy)
        .incompatibleWith("objcheck");

    options
        ->addOptionChaining("net.wireObjectCheck",
                            "",
                            moe::Bool,
                            "inspect client data for validity on receipt (DEFAULT)")
        .hidden()
        .setSources(moe::SourceYAMLConfig);

    options
        ->addOptionChaining("enableExperimentalStorageDetailsCmd",
                            "enableExperimentalStorageDetailsCmd",
                            moe::Switch,
                            "EXPERIMENTAL (UNSUPPORTED). "
                            "Enable command computing aggregate statistics on storage.")
        .hidden()
        .setSources(moe::SourceAllLegacy);

    options
        ->addOptionChaining("operationProfiling.slowOpThresholdMs",
                            "slowms",
                            moe::Int,
                            "value of slow for profile and console log")
        .setDefault(moe::Value(100));

    options
        ->addOptionChaining("operationProfiling.slowOpSampleRate",
                            "slowOpSampleRate",
                            moe::Double,
                            "fraction of slow ops to include in the profile and console log")
        .setDefault(moe::Value(1.0));

    auto ret = addMessageCompressionOptions(options, false);
    if (!ret.isOK()) {
        return ret;
    }

    return Status::OK();
}

Status addWindowsServerOptions(moe::OptionSection* options) {
    options->addOptionChaining("install", "install", moe::Switch, "install Windows service")
        .setSources(moe::SourceAllLegacy);

    options->addOptionChaining("remove", "remove", moe::Switch, "remove Windows service")
        .setSources(moe::SourceAllLegacy);

    options
        ->addOptionChaining(
            "reinstall",
            "reinstall",
            moe::Switch,
            "reinstall Windows service (equivalent to --remove followed by --install)")
        .setSources(moe::SourceAllLegacy);

    options->addOptionChaining("processManagement.windowsService.serviceName",
                               "serviceName",
                               moe::String,
                               "Windows service name");

    options->addOptionChaining("processManagement.windowsService.displayName",
                               "serviceDisplayName",
                               moe::String,
                               "Windows service display name");

    options->addOptionChaining("processManagement.windowsService.description",
                               "serviceDescription",
                               moe::String,
                               "Windows service description");

    options->addOptionChaining("processManagement.windowsService.serviceUser",
                               "serviceUser",
                               moe::String,
                               "account for service execution");

    options->addOptionChaining("processManagement.windowsService.servicePassword",
                               "servicePassword",
                               moe::String,
                               "password used to authenticate serviceUser");

    options->addOptionChaining("service", "service", moe::Switch, "start mongodb service")
        .hidden()
        .setSources(moe::SourceAllLegacy);

    return Status::OK();
}

namespace {
// Helpers for option storage
Status setupBinaryName(const std::vector<std::string>& argv) {
    if (argv.empty()) {
        return Status(ErrorCodes::UnknownError, "Cannot get binary name: argv array is empty");
    }

    // setup binary name
    serverGlobalParams.binaryName = argv[0];
    size_t i = serverGlobalParams.binaryName.rfind('/');
    if (i != string::npos) {
        serverGlobalParams.binaryName = serverGlobalParams.binaryName.substr(i + 1);
    }
    return Status::OK();
}

Status setupCwd() {
    // setup cwd
    boost::system::error_code ec;
    boost::filesystem::path cwd = boost::filesystem::current_path(ec);
    if (ec) {
        return Status(ErrorCodes::UnknownError,
                      "Cannot get current working directory: " + ec.message());
    }
    serverGlobalParams.cwd = cwd.string();
    return Status::OK();
}

Status setArgvArray(const std::vector<std::string>& argv) {
    BSONArrayBuilder b;
    std::vector<std::string> censoredArgv = argv;
    cmdline_utils::censorArgsVector(&censoredArgv);
    for (size_t i = 0; i < censoredArgv.size(); i++) {
        b << censoredArgv[i];
    }
    serverGlobalParams.argvArray = b.arr();
    return Status::OK();
}

Status setParsedOpts(const moe::Environment& params) {
    serverGlobalParams.parsedOpts = params.toBSON();
    cmdline_utils::censorBSONObj(&serverGlobalParams.parsedOpts);
    return Status::OK();
}
}  // namespace

void printCommandLineOpts() {
    log() << "options: " << serverGlobalParams.parsedOpts << endl;
}

Status validateServerOptions(const moe::Environment& params) {
    Status ret = validateBaseOptions(params);
    if (!ret.isOK())
        return ret;

#ifdef _WIN32
    if (params.count("install") || params.count("reinstall")) {
        if (params.count("logpath") &&
            !boost::filesystem::path(params["logpath"].as<string>()).is_absolute()) {
            return Status(ErrorCodes::BadValue,
                          "logpath requires an absolute file path with Windows services");
        }

        if (params.count("config") &&
            !boost::filesystem::path(params["config"].as<string>()).is_absolute()) {
            return Status(ErrorCodes::BadValue,
                          "config requires an absolute file path with Windows services");
        }

        if (params.count("processManagement.pidFilePath") &&
            !boost::filesystem::path(params["processManagement.pidFilePath"].as<string>())
                 .is_absolute()) {
            return Status(ErrorCodes::BadValue,
                          "pidFilePath requires an absolute file path with Windows services");
        }

        if (params.count("security.keyFile") &&
            !boost::filesystem::path(params["security.keyFile"].as<string>()).is_absolute()) {
            return Status(ErrorCodes::BadValue,
                          "keyFile requires an absolute file path with Windows services");
        }
    }
#endif

    bool haveAuthenticationMechanisms = true;
    bool hasAuthorizationEnabled = false;
    if (params.count("security.authenticationMechanisms") &&
        params["security.authenticationMechanisms"].as<std::vector<std::string>>().empty()) {
        haveAuthenticationMechanisms = false;
    }
    if (params.count("setParameter")) {
        std::map<std::string, std::string> parameters =
            params["setParameter"].as<std::map<std::string, std::string>>();
        auto authMechParameter = parameters.find("authenticationMechanisms");
        if (authMechParameter != parameters.end() && authMechParameter->second.empty()) {
            haveAuthenticationMechanisms = false;
        }

        if (parameters.find("internalValidateFeaturesAsMaster") != parameters.end()) {
            // Command line options that are disallowed when internalValidateFeaturesAsMaster is
            // specified.
            if (params.count("replication.replSet")) {
                return Status(ErrorCodes::BadValue,
                              str::stream() <<  //
                                  "Cannot specify both internalValidateFeaturesAsMaster and "
                                  "replication.replSet");
            }
        }
    }
    if ((params.count("security.authorization") &&
         params["security.authorization"].as<std::string>() == "enabled") ||
        params.count("security.clusterAuthMode") || params.count("security.keyFile") ||
        params.count("auth")) {
        hasAuthorizationEnabled = true;
    }
    if (hasAuthorizationEnabled && !haveAuthenticationMechanisms) {
        return Status(ErrorCodes::BadValue,
                      "Authorization is enabled but no authentication mechanisms are present.");
    }

    return Status::OK();
}

Status canonicalizeServerOptions(moe::Environment* params) {
    Status ret = canonicalizeBaseOptions(params);
    if (!ret.isOK())
        return ret;

    // "net.wireObjectCheck" comes from the config file, so override it if either "objcheck" or
    // "noobjcheck" are set, since those come from the command line.
    if (params->count("objcheck")) {
        ret = params->set("net.wireObjectCheck", moe::Value((*params)["objcheck"].as<bool>()));
        if (!ret.isOK()) {
            return ret;
        }
        ret = params->remove("objcheck");
        if (!ret.isOK()) {
            return ret;
        }
    }

    if (params->count("noobjcheck")) {
        ret = params->set("net.wireObjectCheck", moe::Value(!(*params)["noobjcheck"].as<bool>()));
        if (!ret.isOK()) {
            return ret;
        }
        ret = params->remove("noobjcheck");
        if (!ret.isOK()) {
            return ret;
        }
    }

    // "net.unixDomainSocket.enabled" comes from the config file, so override it if
    // "nounixsocket" is set since that comes from the command line.
    if (params->count("nounixsocket")) {
        ret = params->set("net.unixDomainSocket.enabled",
                          moe::Value(!(*params)["nounixsocket"].as<bool>()));
        if (!ret.isOK()) {
            return ret;
        }
        ret = params->remove("nounixsocket");
        if (!ret.isOK()) {
            return ret;
        }
    }

    if (params->count("noauth")) {
        ret = params->set("security.authorization",
                          (*params)["noauth"].as<bool>() ? moe::Value(std::string("disabled"))
                                                         : moe::Value(std::string("enabled")));
        if (!ret.isOK()) {
            return ret;
        }
        ret = params->remove("noauth");
        if (!ret.isOK()) {
            return ret;
        }
    }
    return Status::OK();
}

Status setupServerOptions(const std::vector<std::string>& args) {
    Status ret = setupBinaryName(args);
    if (!ret.isOK()) {
        return ret;
    }

    ret = setupCwd();
    if (!ret.isOK()) {
        return ret;
    }

    ret = setupBaseOptions(args);
    if (!ret.isOK()) {
        return ret;
    }

    return Status::OK();
}

Status storeServerOptions(const moe::Environment& params) {
    Status ret = storeBaseOptions(params);
    if (!ret.isOK()) {
        return ret;
    }

    if (params.count("net.port")) {
        serverGlobalParams.port = params["net.port"].as<int>();
    }

    if (params.count("net.ipv6") && params["net.ipv6"].as<bool>() == true) {
        serverGlobalParams.enableIPv6 = true;
        enableIPv6();
    }

    if (params.count("net.listenBacklog")) {
        serverGlobalParams.listenBacklog = params["net.listenBacklog"].as<int>();
    }

    if (params.count("net.transportLayer")) {
        serverGlobalParams.transportLayer = params["net.transportLayer"].as<std::string>();
        if (serverGlobalParams.transportLayer != "asio") {
            return {ErrorCodes::BadValue, "Unsupported value for transportLayer. Must be \"asio\""};
        }
    }

    if (params.count("net.serviceExecutor")) {
        auto value = params["net.serviceExecutor"].as<std::string>();
        const auto valid = {"synchronous"_sd, "adaptive"_sd};
        if (std::find(valid.begin(), valid.end(), value) == valid.end()) {
            return {ErrorCodes::BadValue, "Unsupported value for serviceExecutor"};
        }
        serverGlobalParams.serviceExecutor = value;
    } else {
        serverGlobalParams.serviceExecutor = "synchronous";
    }

    if (params.count("security.transitionToAuth")) {
        serverGlobalParams.transitionToAuth = params["security.transitionToAuth"].as<bool>();
    }

    if (params.count("security.clusterAuthMode")) {
        std::string clusterAuthMode = params["security.clusterAuthMode"].as<std::string>();

        if (clusterAuthMode == "keyFile") {
            serverGlobalParams.clusterAuthMode.store(ServerGlobalParams::ClusterAuthMode_keyFile);
        } else if (clusterAuthMode == "sendKeyFile") {
            serverGlobalParams.clusterAuthMode.store(
                ServerGlobalParams::ClusterAuthMode_sendKeyFile);
        } else if (clusterAuthMode == "sendX509") {
            serverGlobalParams.clusterAuthMode.store(ServerGlobalParams::ClusterAuthMode_sendX509);
        } else if (clusterAuthMode == "x509") {
            serverGlobalParams.clusterAuthMode.store(ServerGlobalParams::ClusterAuthMode_x509);
        } else {
            return Status(ErrorCodes::BadValue,
                          "unsupported value for clusterAuthMode " + clusterAuthMode);
        }
        serverGlobalParams.authState = ServerGlobalParams::AuthState::kEnabled;
    } else {
        serverGlobalParams.clusterAuthMode.store(ServerGlobalParams::ClusterAuthMode_undefined);
    }

    if (params.count("net.maxIncomingConnections")) {
        serverGlobalParams.maxConns = params["net.maxIncomingConnections"].as<int>();

        if (serverGlobalParams.maxConns < 5) {
            return Status(ErrorCodes::BadValue, "maxConns has to be at least 5");
        }
    }

    if (params.count("net.maxIncomingConnectionsOverride")) {
        auto ranges = params["net.maxIncomingConnectionsOverride"].as<std::vector<std::string>>();
        for (const auto& range : ranges) {
            auto swr = CIDR::parse(range);
            if (!swr.isOK()) {
                serverGlobalParams.maxConnsOverride.push_back(range);
            } else {
                serverGlobalParams.maxConnsOverride.push_back(std::move(swr.getValue()));
            }
        }
    }

    if (params.count("net.reservedAdminThreads")) {
        serverGlobalParams.reservedAdminThreads = params["net.reservedAdminThreads"].as<int>();
    }

    if (params.count("net.wireObjectCheck")) {
        serverGlobalParams.objcheck = params["net.wireObjectCheck"].as<bool>();
    }

    if (params.count("net.bindIp")) {
        std::string bind_ip = params["net.bindIp"].as<std::string>();
        if (bind_ip == "*") {
            serverGlobalParams.bind_ips.emplace_back("0.0.0.0");
            if (params.count("net.ipv6") && params["net.ipv6"].as<bool>()) {
                serverGlobalParams.bind_ips.emplace_back("::");
            }
        } else {
            boost::split(serverGlobalParams.bind_ips,
                         bind_ip,
                         [](char c) { return c == ','; },
                         boost::token_compress_on);
        }
    }

    for (auto& ip : serverGlobalParams.bind_ips) {
        boost::algorithm::trim(ip);
    }

#ifndef _WIN32
    if (params.count("net.unixDomainSocket.pathPrefix")) {
        serverGlobalParams.socket = params["net.unixDomainSocket.pathPrefix"].as<string>();
    }

    if (params.count("net.unixDomainSocket.enabled")) {
        serverGlobalParams.noUnixSocket = !params["net.unixDomainSocket.enabled"].as<bool>();
    }
    if (params.count("net.unixDomainSocket.filePermissions")) {
        serverGlobalParams.unixSocketPermissions =
            params["net.unixDomainSocket.filePermissions"].as<int>();
    }

    if ((params.count("processManagement.fork") &&
         params["processManagement.fork"].as<bool>() == true) &&
        (!params.count("shutdown") || params["shutdown"].as<bool>() == false)) {
        serverGlobalParams.doFork = true;
    }
#endif  // _WIN32

    if (serverGlobalParams.doFork && serverGlobalParams.logpath.empty() &&
        !serverGlobalParams.logWithSyslog) {
        return Status(ErrorCodes::BadValue, "--fork has to be used with --logpath or --syslog");
    }

    if (params.count("security.keyFile")) {
        serverGlobalParams.keyFile =
            boost::filesystem::absolute(params["security.keyFile"].as<string>()).generic_string();
        serverGlobalParams.authState = ServerGlobalParams::AuthState::kEnabled;
    }

    if (serverGlobalParams.transitionToAuth ||
        (params.count("security.authorization") &&
         params["security.authorization"].as<std::string>() == "disabled")) {
        serverGlobalParams.authState = ServerGlobalParams::AuthState::kDisabled;
    } else if (params.count("security.authorization") &&
               params["security.authorization"].as<std::string>() == "enabled") {
        serverGlobalParams.authState = ServerGlobalParams::AuthState::kEnabled;
    }

    if (params.count("processManagement.pidFilePath")) {
        serverGlobalParams.pidFile = params["processManagement.pidFilePath"].as<string>();
    }

    if (params.count("processManagement.timeZoneInfo")) {
        serverGlobalParams.timeZoneInfoPath = params["processManagement.timeZoneInfo"].as<string>();
    }

    if (!params.count("security.clusterAuthMode") && params.count("security.keyFile")) {
        serverGlobalParams.clusterAuthMode.store(ServerGlobalParams::ClusterAuthMode_keyFile);
    }
    int clusterAuthMode = serverGlobalParams.clusterAuthMode.load();
    if (serverGlobalParams.transitionToAuth &&
        (clusterAuthMode != ServerGlobalParams::ClusterAuthMode_keyFile &&
         clusterAuthMode != ServerGlobalParams::ClusterAuthMode_x509)) {
        return Status(ErrorCodes::BadValue,
                      "--transitionToAuth must be used with keyFile or x509 authentication");
    }

    ret = storeMessageCompressionOptions(params);
    if (!ret.isOK()) {
        return ret;
    }

    return Status::OK();
}

}  // namespace mongo