2017-05-26 08:24:56 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
nsjail - config parsing
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
Copyright 2017 Google Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2017-05-26 10:25:55 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
#if !defined(NSJAIL_WITH_PROTOBUF)
|
2017-05-26 08:24:56 +08:00
|
|
|
bool configParse(struct nsjconf_t * nsjconf UNUSED, const char *file UNUSED)
|
|
|
|
{
|
|
|
|
LOG_W("nsjail was not compiled with the protobuf-c library");
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-26 10:15:45 +08:00
|
|
|
#else /* !defined(NSJAIL_WITH_PROTOBUF) */
|
2017-05-26 08:24:56 +08:00
|
|
|
|
|
|
|
#include "config.pb-c.h"
|
2017-05-26 10:25:55 +08:00
|
|
|
#include "protobuf-c-text.h"
|
2017-05-26 08:24:56 +08:00
|
|
|
|
|
|
|
static bool configParseInternal(struct nsjconf_t *nsjconf, Nsjail__NsJailConfig * njc)
|
|
|
|
{
|
|
|
|
if (njc->has_chroot) {
|
|
|
|
nsjconf->chroot = utilStrDupLen((char *)njc->chroot.data, njc->chroot.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool configParse(struct nsjconf_t * nsjconf, const char *file)
|
|
|
|
{
|
2017-05-26 10:25:55 +08:00
|
|
|
FILE *f = fopen(file, "rb");
|
|
|
|
if (f == NULL) {
|
|
|
|
PLOG_W("Couldn't open '%s' for reading", file);
|
2017-05-26 08:24:56 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-26 10:25:55 +08:00
|
|
|
ProtobufCTextError error;
|
|
|
|
Nsjail__NsJailConfig *njc =
|
|
|
|
(Nsjail__NsJailConfig *) protobuf_c_text_from_file(&nsjail__ns_jail_config__descriptor,
|
|
|
|
f, &error, NULL);
|
2017-05-26 08:24:56 +08:00
|
|
|
if (njc == NULL) {
|
2017-05-26 10:25:55 +08:00
|
|
|
LOG_W("Couldn't parse config from '%s': %s", file, error.error_txt);
|
|
|
|
fclose(f);
|
2017-05-26 08:24:56 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = configParseInternal(nsjconf, njc);
|
2017-05-26 10:25:55 +08:00
|
|
|
fclose(f);
|
2017-05-26 08:24:56 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2017-05-26 10:15:45 +08:00
|
|
|
#endif /* !defined(NSJAIL_WITH_PROTOBUF) */
|