Lines Matching refs:ns
139 void ns_free(ns_t *ns)
141 if (!ns) {
144 if (ns->ns_dsos) {
145 __libc_free(ns->ns_dsos);
146 ns->ns_dsos = NULL;
148 if (ns->ns_name) {
149 __libc_free(ns->ns_name);
150 ns->ns_name = NULL;
152 if (ns->env_paths) {
153 __libc_free(ns->env_paths);
154 ns->env_paths = NULL;
156 if (ns->lib_paths) {
157 __libc_free(ns->lib_paths);
158 ns->lib_paths = NULL;
160 if (ns->asan_lib_paths) {
161 __libc_free(ns->asan_lib_paths);
162 ns->asan_lib_paths = NULL;
164 strlist_free(ns->permitted_paths);
165 strlist_free(ns->asan_permitted_paths);
166 strlist_free(ns->allowed_libs);
167 nsinherits_free(ns->ns_inherits);
168 __libc_free(ns);
171 void ns_add_dso(ns_t *ns, struct dso *dso)
173 if (!ns || !dso) {
176 if (!ns->ns_dsos) {
177 ns->ns_dsos = dsolist_alloc();
179 if (!ns->ns_dsos) {
182 if (ns->ns_dsos->num == ns->ns_dsos->size) {
184 dsolist_realloc(ns->ns_dsos);
186 if (ns->ns_dsos->num < ns->ns_dsos->size) {
188 ns->ns_dsos->dsos[ns->ns_dsos->num] = dso;
189 ns->ns_dsos->num++;
222 void nslist_add_ns(ns_t *ns)
224 if (!ns) {
234 g_ns_list.nss[g_ns_list.num] = ns;
246 void ns_set_name(ns_t *ns, const char *name)
248 if (!ns || !name) {
251 if (ns->ns_name) __libc_free(ns->ns_name);
252 ns->ns_name = ld_strdup(name);
253 strtrim(ns->ns_name);
254 LD_LOGD("ns_set_name ns_name:%{public}s.", ns->ns_name);
257 void ns_set_env_paths(ns_t *ns, const char *env_paths)
259 if (!ns) {
262 if (ns->env_paths) __libc_free(ns->env_paths);
264 ns->env_paths = ld_strdup(env_paths);
265 strtrim(ns->env_paths);
267 ns->env_paths = NULL;
269 LD_LOGD("ns_set_env_paths ns[%{public}s] env_paths:%{public}s.", ns->ns_name, ns->env_paths);
272 void ns_set_lib_paths(ns_t *ns, const char *lib_paths)
274 if (!ns) {
277 if (ns->lib_paths) __libc_free(ns->lib_paths);
279 ns->lib_paths = ld_strdup(lib_paths);
280 strtrim(ns->lib_paths);
282 ns->lib_paths = NULL;
284 LD_LOGD("ns_set_lib_paths ns[%{public}s] lib_paths:%{public}s.", ns->ns_name, ns->lib_paths);
287 void ns_set_asan_lib_paths(ns_t *ns, const char *asan_lib_paths)
289 if (!ns) {
292 if (ns->asan_lib_paths) {
293 __libc_free(ns->asan_lib_paths);
296 ns->asan_lib_paths = ld_strdup(asan_lib_paths);
297 strtrim(ns->asan_lib_paths);
299 ns->asan_lib_paths = NULL;
301 LD_LOGD("ns_set_asan_lib_paths ns[%{public}s] asan_lib_paths:%{public}s.", ns->ns_name, ns->asan_lib_paths);
304 void ns_set_permitted_paths(ns_t *ns, const char *permitted_paths)
306 if (!ns) {
309 if (ns->permitted_paths) strlist_free(ns->permitted_paths);
310 ns->permitted_paths = strsplit(permitted_paths, ":");
311 LD_LOGD("ns_set_permitted_paths ns[%{public}s] permitted_paths:%{public}s.", ns->ns_name, permitted_paths);
314 void ns_set_asan_permitted_paths(ns_t *ns, const char *asan_permitted_paths)
316 if (!ns) {
319 if (ns->asan_permitted_paths) {
320 strlist_free(ns->asan_permitted_paths);
322 ns->asan_permitted_paths = strsplit(asan_permitted_paths, ":");
323 LD_LOGD("ns_set_asan_permitted_paths ns[%{public}s] asan_permitted_paths:%{public}s.",
324 ns->ns_name,
328 void ns_set_separated(ns_t *ns, bool separated)
330 if (!ns) {
333 ns->separated = separated;
334 LD_LOGD("ns_set_separated ns[%{public}s] separated:%{public}d.", ns->ns_name, ns->separated);
337 void ns_set_allowed_libs(ns_t *ns, const char *allowed_libs)
339 if (!ns) {
343 if (ns->allowed_libs) strlist_free(ns->allowed_libs);
344 ns->allowed_libs = NULL;
348 if (strtrim(a_libs) > 0) ns->allowed_libs = strsplit(a_libs, ":");
351 LD_LOGD("ns_set_allowed_libs ns[%{public}s] allowed_libs:%{public}s.", ns->ns_name, allowed_libs);
372 static ns_inherit *find_ns_inherit(ns_t *ns, ns_t *inherited)
374 if (!ns || !inherited) {
377 if (ns->ns_inherits) {
378 for (size_t i = 0; i < ns->ns_inherits->num; i++) {
379 if (ns->ns_inherits->inherits[i]->inherited_ns == inherited) return ns->ns_inherits->inherits[i];
383 "find_ns_inherit ns[%{public}s] ns_inherited[%{public}s] failed,return NULL!", ns->ns_name, inherited->ns_name);
387 void ns_add_inherit(ns_t *ns, ns_t *ns_inherited, const char *shared_libs)
390 if (!ns || !ns_inherited) {
394 ns_inherit *inherit = find_ns_inherit(ns, ns_inherited);
398 LD_LOGE("ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] calloc failed!",
399 ns->ns_name,
405 LD_LOGD("ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] need_add is true.",
406 ns->ns_name,
424 "ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] not need_add!", ns->ns_name, ns_inherited->ns_name);
428 if (!ns->ns_inherits) {
429 ns->ns_inherits = nsinherits_alloc();
432 if (!ns->ns_inherits) {
434 LD_LOGD("ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] nsinherits_alloc failed!",
435 ns->ns_name,
441 if (ns->ns_inherits->num == ns->ns_inherits->size) {
443 LD_LOGD("ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] list is full, realloc size to double!",
444 ns->ns_name,
446 nsinherits_realloc(ns->ns_inherits);
449 if (ns->ns_inherits->num < ns->ns_inherits->size) {
451 LD_LOGD("ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] realloc success!",
452 ns->ns_name,
454 ns->ns_inherits->inherits[ns->ns_inherits->num] = inherit;
455 ns->ns_inherits->num++;
458 LD_LOGD("ns_add_inherit ns[%{public}s] ns_inherited[%{public}s] realloc failed!",
459 ns->ns_name,
468 bool is_accessible(ns_t *ns, const char *lib_pathname, bool is_asan, bool check_inherited)
470 if (check_inherited && !ns->separated) {
471 LD_LOGD("is_accessible ns [%{public}s] is not separated, return true.", ns->ns_name);
474 if (ns->allowed_libs) {
479 for (; i < ns->allowed_libs->num; i++) {
480 if (strcmp(shortname, ns->allowed_libs->strs[i]) == 0) {
484 if (i >= ns->allowed_libs->num) {
485 LD_LOGD("is_accessible ns [%{public}s] lib_pathname [%{public}s] is not in allowed_libs, return false.",
486 ns->ns_name,
493 if (ns->env_paths && (paths = strsplit(ns->env_paths, ":"))) {
499 LD_LOGD("is_accessible ns [%{public}s] lib_pathname [%{public}s] in env_paths, return true.",
500 ns->ns_name,
510 if (check_asan_path(ns, lib_pathname)) {
511 LD_LOGD("is_accessible ns [%{public}s] lib_pathname [%{public}s] check_asan_path success, return true.",
512 ns->ns_name,
518 if (ns->lib_paths && (paths = strsplit(ns->lib_paths, ":"))) {
525 LD_LOGD("is_accessible ns [%{public}s] lib_pathname [%{public}s] in lib_paths, return true.",
526 ns->ns_name,
534 if (ns->permitted_paths) {
535 for (size_t i = 0; i < ns->permitted_paths->num; i++) {
536 size_t len = strlen(ns->permitted_paths->strs[i]);
537 if (strncmp(lib_pathname, ns->permitted_paths->strs[i], len) == 0 &&
539 LD_LOGD("is_accessible ns [%{public}s] lib_pathname [%{public}s] in permitted_paths, return true.",
540 ns->ns_name,
549 bool check_asan_path(ns_t *ns, const char *lib_pathname)
552 if (ns->asan_lib_paths && (paths = strsplit(ns->asan_lib_paths, ":"))) {
559 LD_LOGD("check_asan_path ns [%{public}s] lib_pathname [%{public}s] in asan_lib_paths, return true.",
560 ns->ns_name,
567 if (ns->asan_permitted_paths) {
568 for (size_t i = 0; i < ns->asan_permitted_paths->num; i++) {
569 size_t len = strlen(ns->asan_permitted_paths->strs[i]);
570 if (strncmp(lib_pathname, ns->asan_permitted_paths->strs[i], len) == 0 &&
573 "check_asan_path ns [%{public}s] lib_pathname [%{public}s] in asan_permitted_paths, return true.",
574 ns->ns_name,
581 "check_asan_path ns [%{public}s] lib_pathname [%{public}s] failed, return false.", ns->ns_name, lib_pathname);
606 void ns_set_flag(ns_t *ns, int flag)
608 if (!ns) {
611 ns->flag = flag;
612 LD_LOGD("ns_set_flag ns[%{public}s] flag:%{public}d.", ns->ns_name, ns->flag);