Esempio n. 1
0
static int fix_rel_pathnames(void)
{
	if (tls_cfg_file.s) {
		tls_cfg_file.s = get_abs_pathname(NULL, &tls_cfg_file);
		if (tls_cfg_file.s == NULL) return -1;
		tls_cfg_file.len = strlen(tls_cfg_file.s);
	}
	
	if (mod_params.pkey_file.s) {
		mod_params.pkey_file.s = get_abs_pathname(NULL, &mod_params.pkey_file);
		if (mod_params.pkey_file.s == NULL) return -1;
		mod_params.pkey_file.len = strlen(mod_params.pkey_file.s);
	}
	
	if (mod_params.ca_file.s) {
		mod_params.ca_file.s = get_abs_pathname(NULL, &mod_params.ca_file);
		if (mod_params.ca_file.s == NULL) return -1;
		mod_params.ca_file.len = strlen(mod_params.ca_file.s);
	}
	
	if (mod_params.cert_file.s) {
		mod_params.cert_file.s = get_abs_pathname(NULL, &mod_params.cert_file);
		if (mod_params.cert_file.s == NULL) return -1;
		mod_params.cert_file.len = strlen(mod_params.cert_file.s);
	}
	
	return 0;
}
Esempio n. 2
0
/** cfg framework callback for fixing pathnames. */
static int fix_rel_pathname(void* cfg_h, str* gname, str* name, void** val)
{
	str* f;
	str new_f;
	/* the cfg framework will immediately "clone" the value so
	   we can pass a pointer to a temporary static buffer to it
	   (using a dyn. alloc'd buffer would introduce the additional
	    problem of having to free it somehow) */
	static char path_buf[MAX_PATH_SIZE];

	f = *val;
	/* use absolute paths, except when the path starts with
	   '.' (in this case leave it as it is) */
	if (f && f->s && f->len && *f->s != '.' && *f->s != '/') {
		new_f.s = get_abs_pathname(0, f);
		if (new_f.s == 0)
			return -1;
		new_f.len = strlen(new_f.s);
		if (new_f.len >= MAX_PATH_SIZE) {
			ERR("%.*s.%.*s path too long (%d bytes): \"%.*s\"\n",
					gname->len, gname->s, name->len, name->s,
					new_f.len, new_f.len, new_f.s);
			pkg_free(new_f.s);
			return -1;
		}
		memcpy(path_buf, new_f.s, new_f.len);
		pkg_free(new_f.s);
		new_f.s = path_buf;
		*f = new_f;
	}
	return 0;
}
Esempio n. 3
0
int flat_uri(db_uri_t* uri)
{
	struct flat_uri* furi;

	if ((furi = (struct flat_uri*)pkg_malloc(sizeof(*furi))) == NULL) {
		ERR("flatstore: No memory left\n");
		return -1;
	}
	memset(furi, '\0', sizeof(*furi));
	if (db_drv_init(&furi->drv, flat_uri_free) < 0) goto error;

	if ((furi->path.s = get_abs_pathname(NULL, &uri->body)) == NULL) {
		ERR("flatstore: Error while obtaining absolute pathname for '%.*s'\n",
			STR_FMT(&uri->body));
		goto error;
	}
	furi->path.len = strlen(furi->path.s);

	DB_SET_PAYLOAD(uri, furi);
	return 0;

 error:
	if (furi) {
		if (furi->path.s) pkg_free(furi->path.s);
		db_drv_free(&furi->drv);
		pkg_free(furi);
	}
	return -1;	
}
Esempio n. 4
0
/**
 * @brief Fix pathnames when loading domain keys or other list
 * 
 * Fix pathnames, to be used when loading the domain key, cert, ca list a.s.o.
 * It will replace path with a fixed shm allocated version. Assumes path->s
 * was shm allocated.
 * @param path path to be fixed. If it starts with '.' or '/' is left alone
 * (forced "relative" or "absolute" path). Otherwise the path is considered 
 * to be relative to the main config file directory
 * (e.g. for /etc/ser/ser.cfg => /etc/ser/\<path\>).
 * @return  0 on success, -1 on error
 */
int fix_shm_pathname(str* path)
{
	str new_path;
	char *abs_path;

	if(path->s && path->len && *path->s != '.' && *path->s != '/') {
		abs_path = get_abs_pathname(0, path);
		if(abs_path == 0) {
			LM_ERR("get abs pathname failed\n");
			return -1;
		}
		new_path.len = strlen(abs_path);
		new_path.s = shm_malloc(new_path.len + 1);
		if(new_path.s == 0) {
			LM_ERR("no more shm memory\n");
			pkg_free(abs_path);
			return -1;
		}
		memcpy(new_path.s, abs_path, new_path.len);
		new_path.s[new_path.len] = 0;
		shm_free(path->s);
		pkg_free(abs_path);
		*path = new_path;
	}
	return 0;
}
Esempio n. 5
0
/** fix pathnames.
 * to be used on start-up, with pkg_alloc'ed path names  (path->s).
 * @param path - path to be fixed. If it starts with '.' or '/' is left alone
 *               (forced "relative" or "absolute" path). Otherwise the path
 *               is considered to be relative to the main config file directory
 *               (e.g. for /etc/ser/ser.cfg => /etc/ser/\<path\>).
 * @param def - default value used if path->s is empty (path->s == 0).
 * @return  0 on success, -1 on error.
 */
static int fix_initial_pathname(str* path, char* def)
{
	str new_path;
	if (path->s && path->len && *path->s != '.' && *path->s != '/') {
		new_path.s = get_abs_pathname(0, path);
		if (new_path.s == 0) return -1;
		new_path.len = strlen(new_path.s);
		pkg_free(path->s);
		*path = new_path;
	} else if (path->s == 0 && def) {
		/* use defaults */
		new_path.len = strlen(def);
		new_path.s = def;
		new_path.s = get_abs_pathname(0, &new_path);
		if (new_path.s == 0) return -1;
		new_path.len = strlen(new_path.s);
		*path = new_path;
	}
	return 0;
}
Esempio n. 6
0
/** intialize the config parser.
 * @param basedir - path to the config file name. If 0 the path
 *               (base directory) of the main ser.cfg file will be used, else
 *               basedir will be concatenated to the filename. It will be
 *               used only if filename is not an absolute path.
 * @param filename - config filename (can include path elements).
 * @return 0 on error, !=0 on success.
 */
cfg_parser_t* cfg_parser_init(str* basedir, str* filename)
{
	cfg_parser_t* st;
	char* pathname, *base, *abs_pathname;

	abs_pathname = NULL;
	pathname = filename->s;
	st = NULL;
	base = NULL;
	
	/* if basedir == 0 or != "" get_abs_pathname */
	if (basedir == 0  || basedir->len != 0) {
		if ((abs_pathname = get_abs_pathname(basedir, filename)) == NULL) {
			ERR("cfg_parser: Error while converting %.*s to absolute"
					" pathname\n", STR_FMT(filename));
			goto error;
		}
		pathname = abs_pathname;
	}

	if ((base = get_base_name(filename)) == NULL) goto error;

	if ((st = (cfg_parser_t*)pkg_malloc(sizeof(*st))) == NULL) {
		ERR("cfg_parser: No memory left\n");
		goto error;
	}
	memset(st, '\0', sizeof(*st));

	if ((st->f = fopen(pathname, "r")) == NULL) {
		ERR("cfg_parser: Unable to open file '%s'\n", pathname);
		goto error;
	}

	if (abs_pathname) pkg_free(abs_pathname);

	st->file = base;
	st->line = 1;
	st->col = 0;
	return st;

 error:
	if (st) {
		if (st->f) fclose(st->f);
		pkg_free(st);
	}
	if (base) pkg_free(base);
	if (abs_pathname) pkg_free(abs_pathname);
	return NULL;
}
Esempio n. 7
0
/**
 * @brief Fix pathnames when loading domain keys or other list
 * 
 * Fix pathnames, to be used when loading the domain key, cert, ca list a.s.o.
 * It will replace path with a fixed shm allocated version. Assumes path->s
 * was shm allocated.
 * @param path path to be fixed. If it starts with '.' or '/' is left alone
 * (forced "relative" or "absolute" path). Otherwise the path is considered 
 * to be relative to the main config file directory
 * (e.g. for /etc/ser/ser.cfg => /etc/ser/\<path\>).
 * @return  0 on success, -1 on error
 */
int fix_shm_pathname(str* path)
{
	str new_path;
	char* abs_path;
	
	if (path->s && path->len && *path->s != '.' && *path->s != '/') {
		abs_path = get_abs_pathname(0, path);
		if (abs_path == 0) return -1;
		new_path.len = strlen(abs_path);
		new_path.s = shm_malloc(new_path.len + 1);
		memcpy(new_path.s, abs_path, new_path.len);
		new_path.s[new_path.len] = 0;
		shm_free(path->s);
		*path = new_path;
	}
	return 0;
}