namespace.c 16.4 KB
Newer Older
Y
yangwenjun 已提交
1 2
#include "namespace.h"

W
wangjiahui 已提交
3 4 5
#include "ld_log.h"
#include "strops.h"

Y
yangwenjun 已提交
6 7 8
static ns_t g_ns_default;
static nslist g_ns_list;

9
#ifndef NSLIST_DEFAULT_SIZE
Y
yangwenjun 已提交
10
#define NSLIST_DEFAULT_SIZE 16
11 12
#endif
#ifndef DSOLIST_DEFAULT_SIZE
Y
yangwenjun 已提交
13
#define DSOLIST_DEFAULT_SIZE 16
14 15
#endif
#ifndef INHERIT_DEFAULT_SIZE
Y
yangwenjun 已提交
16
#define INHERIT_DEFAULT_SIZE 16
17
#endif
Y
yangwenjun 已提交
18 19 20 21 22 23 24 25 26 27

static ns_inherit_list *nsinherits_alloc()
{
    ns_inherit_list *nsinl;
    nsinl = (ns_inherit_list *)calloc(1, sizeof *nsinl) ;

    if (nsinl) {
        nsinl->size = INHERIT_DEFAULT_SIZE;
        nsinl->inherits = (ns_inherit **)calloc(INHERIT_DEFAULT_SIZE, sizeof *nsinl->inherits);
        if (!nsinl->inherits) {
W
wangjiahui 已提交
28
            LD_LOGW("nsinherits_alloc failed,return NULL!\n");
Y
yangwenjun 已提交
29 30 31 32 33 34 35 36 37
            free(nsinl);
            nsinl = NULL;
        }
    }
    return nsinl;
}

static void nsinherits_free(ns_inherit_list *nsinl)
{
W
wangjiahui 已提交
38 39 40 41
    if (!nsinl) {
        LD_LOGW("nsinherits_free failed,nsinl is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
42 43 44 45 46 47 48 49 50 51
    for (size_t i=0; i<nsinl->num; i++) {
        strlist_free(nsinl->inherits[i]->shared_libs);
        free(nsinl->inherits[i]);
    }
    free(nsinl->inherits);
    free(nsinl);
}

static void nsinherits_realloc(ns_inherit_list *nsinl)
{
W
wangjiahui 已提交
52 53 54 55
    if (!nsinl) {
        LD_LOGW("nsinherits_realloc failed,nsinl is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
56 57 58 59
    size_t size = 2*nsinl->size;
    if (size) {
        ns_inherit **inherits;
        inherits = (ns_inherit **)realloc(nsinl->inherits, size * (sizeof *nsinl->inherits));
W
wangjiahui 已提交
60 61 62 63
        if (!inherits) {
            LD_LOGW("nsinherits_realloc failed!\n");
            return;
        }
Y
yangwenjun 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        nsinl->size = size;
        nsinl->inherits = inherits;
    }
    return;
}

static dsolist *dsolist_alloc()
{
    dsolist *dsol;
    dsol = (dsolist *)calloc(1, sizeof *dsol) ;

    if (dsol) {
        dsol->size = DSOLIST_DEFAULT_SIZE ;
        dsol->dsos = (struct dso**)calloc(DSOLIST_DEFAULT_SIZE, sizeof *dsol->dsos);
        if (!dsol->dsos) {
W
wangjiahui 已提交
79
            LD_LOGW("dsolist_alloc failed,return NULL!\n");
Y
yangwenjun 已提交
80 81 82 83 84 85 86 87 88
            free(dsol);
            dsol = NULL;
        }
    }
    return dsol ;
}

static void dsolist_realloc(dsolist *dsol)
{
W
wangjiahui 已提交
89 90 91 92
    if (!dsol) {
        LD_LOGW("dsolist_realloc failed,dsol is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
93 94 95 96
    size_t size = 2*dsol->size;
    if (size) {
        struct dso **ds;
        ds = (struct dso **)realloc(dsol->dsos, size * (sizeof *dsol->dsos));
W
wangjiahui 已提交
97 98 99 100
        if (!ds) {
            LD_LOGW("dsolist_realloc failed!\n");
            return;
        }
Y
yangwenjun 已提交
101 102 103 104 105 106 107 108 109 110 111
        dsol->size = size;
        dsol->dsos = ds;
    }
    return;
}

ns_t *ns_alloc()
{
    ns_t *nst = (ns_t *)calloc(1, sizeof *nst);
    nst->ns_dsos = dsolist_alloc();
    if (!nst->ns_dsos) {
W
wangjiahui 已提交
112
        LD_LOGW("ns_alloc failed,return NULL!\n");
Y
yangwenjun 已提交
113 114 115 116 117 118 119 120
        free(nst);
        nst = NULL;
    }
    return nst;
}

void ns_free(ns_t *ns)
{
W
wangjiahui 已提交
121 122 123 124
    if (!ns) {
        LD_LOGW("ns_free failed!\n");
        return;
    }
Y
yangwenjun 已提交
125 126 127
    free(ns->ns_name);
    free(ns->env_paths);
    free(ns->lib_paths);
W
wangjiahui 已提交
128
    free(ns->asan_lib_paths);
Y
yangwenjun 已提交
129
    strlist_free(ns->permitted_paths);
W
wangjiahui 已提交
130
    strlist_free(ns->asan_permitted_paths);
Y
yangwenjun 已提交
131 132 133 134 135 136 137
    strlist_free(ns->allowed_libs);
    nsinherits_free(ns->ns_inherits);
    free(ns);
}

void ns_add_dso(ns_t *ns, struct dso *dso)
{
W
wangjiahui 已提交
138 139 140 141
    if (!ns||!dso) {
        LD_LOGW("ns_add_dso failed,ns or dso is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
142 143 144
    if (!ns->ns_dsos) {
        ns->ns_dsos = dsolist_alloc();
    }
W
wangjiahui 已提交
145 146 147 148
    if (!ns->ns_dsos) {
        LD_LOGW("ns_add_dso failed,ns->ns_dsos is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    if (ns->ns_dsos->num == ns->ns_dsos->size) {
        /* if list is full, realloc size to double*/
        dsolist_realloc(ns->ns_dsos);
    }
    if (ns->ns_dsos->num < ns->ns_dsos->size) {
        /* realloc succ */
        ns->ns_dsos->dsos[ns->ns_dsos->num] = dso;
        ns->ns_dsos->num++;
    }
    return;
}

nslist *nslist_init()
{
    g_ns_list.size = NSLIST_DEFAULT_SIZE;
    g_ns_list.num = 0;
    g_ns_list.nss = (ns_t **)calloc(NSLIST_DEFAULT_SIZE, sizeof *g_ns_list.nss);
    if (!g_ns_list.nss) {
W
wangjiahui 已提交
167
        LD_LOGW("nslist_init failed!\n");
Y
yangwenjun 已提交
168 169 170 171 172 173 174 175 176 177 178
        return NULL;
    }
    return &g_ns_list;
}

static void nslist_realloc()
{
    size_t size = 2*g_ns_list.size;
    if (size) {
        ns_t **nss;
        nss = (ns_t **)realloc(g_ns_list.nss, size * (sizeof *g_ns_list.nss));
W
wangjiahui 已提交
179 180 181 182
        if (!nss) {
            LD_LOGW("nslist_realloc failed!\n");
            return;
        }
Y
yangwenjun 已提交
183 184 185 186 187 188 189 190
        g_ns_list.size = size;
        g_ns_list.nss = nss;
    }
    return;
}

void nslist_add_ns(ns_t *ns)
{
W
wangjiahui 已提交
191 192 193 194
    if (!ns) {
        LD_LOGW("nslist_add_ns failed,ns is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
   
    if (g_ns_list.num == g_ns_list.size) {
        /* if list is full, realloc size to double*/
        nslist_realloc();
    }
    if (g_ns_list.num < g_ns_list.size) {
        /* realloc succ */
        g_ns_list.nss[g_ns_list.num] = ns;
        g_ns_list.num++;
    }
    return;
}

ns_t *get_default_ns()
{
    return &g_ns_default;
}

/* set namespace attributes*/
void ns_set_name(ns_t *ns, const char *name)
{
W
wangjiahui 已提交
216 217 218 219
    if (!ns || !name) {
        LD_LOGW("ns_set_name failed,ns or name is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
220 221 222
    if (ns->ns_name) free(ns->ns_name);
    ns->ns_name = strdup(name);
    strtrim(ns->ns_name);
W
wangjiahui 已提交
223
    LD_LOGD("ns_set_name ns_name:%s.\n", ns->ns_name);
Y
yangwenjun 已提交
224 225 226 227
}

void ns_set_env_paths(ns_t *ns, const char *env_paths)
{
W
wangjiahui 已提交
228 229 230 231
    if (!ns) {
        LD_LOGW("ns_set_env_paths failed,ns is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
232 233 234 235 236 237 238
    if (ns->env_paths) free(ns->env_paths);
    if (env_paths) {
        ns->env_paths = strdup(env_paths);
        strtrim(ns->env_paths);
    } else {
        ns->env_paths = NULL;
    }
W
wangjiahui 已提交
239
    LD_LOGD("ns_set_env_paths ns[%s] env_paths:%s.\n", ns->ns_name, ns->env_paths);
Y
yangwenjun 已提交
240 241 242 243
}

void ns_set_lib_paths(ns_t *ns, const char *lib_paths)
{
W
wangjiahui 已提交
244 245 246 247
    if (!ns) {
        LD_LOGW("ns_set_lib_paths failed,ns is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
248 249 250 251 252 253 254
    if (ns->lib_paths) free(ns->lib_paths);
    if (lib_paths) {
        ns->lib_paths = strdup(lib_paths);
        strtrim(ns->lib_paths);
    } else {
        ns->lib_paths = NULL;
    }
W
wangjiahui 已提交
255
    LD_LOGD("ns_set_lib_paths ns[%s] lib_paths:%s.\n", ns->ns_name, ns->lib_paths);
Y
yangwenjun 已提交
256 257
}

W
wangjiahui 已提交
258
void ns_set_asan_lib_paths(ns_t *ns, const char *asan_lib_paths)
Y
yangwenjun 已提交
259
{
W
wangjiahui 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    if (!ns) {
        LD_LOGW("ns_set_asan_lib_paths failed,ns is NULL!\n");
        return;
    }
    if (ns->asan_lib_paths) {
        free(ns->asan_lib_paths);
    }
    if (asan_lib_paths) {
        ns->asan_lib_paths = strdup(asan_lib_paths);
        strtrim(ns->asan_lib_paths);
    } else {
        ns->asan_lib_paths = NULL;
    }
    LD_LOGD("ns_set_asan_lib_paths ns[%s] asan_lib_paths:%s.\n", ns->ns_name, ns->asan_lib_paths);
}

void ns_set_permitted_paths(ns_t *ns, const char *permitted_paths)
{
    if (!ns) {
        LD_LOGW("ns_set_permitted_paths failed,ns is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
282 283
    if (ns->permitted_paths) strlist_free(ns->permitted_paths);
    ns->permitted_paths = strsplit(permitted_paths,":");
W
wangjiahui 已提交
284
    LD_LOGD("ns_set_permitted_paths ns[%s] permitted_paths:%s.\n", ns->ns_name, permitted_paths);
Y
yangwenjun 已提交
285 286
}

W
wangjiahui 已提交
287
void ns_set_asan_permitted_paths(ns_t *ns, const char *asan_permitted_paths)
Y
yangwenjun 已提交
288
{
W
wangjiahui 已提交
289 290 291 292 293 294 295 296
    if (!ns) {
        LD_LOGW("ns_set_asan_permitted_paths failed,ns is NULL!\n");
        return;
    }
    if (ns->asan_permitted_paths) {
        strlist_free(ns->asan_permitted_paths);
    }
    ns->asan_permitted_paths = strsplit(asan_permitted_paths, ":");
W
wangjiahui 已提交
297
    LD_LOGD("ns_set_asan_permitted_paths ns[%s] asan_permitted_paths:%s.\n", ns->ns_name, asan_permitted_paths);
W
wangjiahui 已提交
298 299 300 301 302 303 304 305
}

void ns_set_separated(ns_t *ns, bool separated)
{
    if (!ns) {
        LD_LOGW("ns_set_separated failed,ns is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
306
    ns->separated = separated;
W
wangjiahui 已提交
307
    LD_LOGD("ns_set_separated ns[%s] separated:%d.\n", ns->ns_name, ns->separated);
Y
yangwenjun 已提交
308 309 310 311
}

void ns_set_allowed_libs(ns_t *ns, const char *allowed_libs)
{
W
wangjiahui 已提交
312 313 314 315
    if (!ns) {
        LD_LOGW("ns_set_allowed_libs failed,ns is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
316 317 318 319 320 321 322 323 324
    
    if (ns->allowed_libs) strlist_free(ns->allowed_libs);
    ns->allowed_libs = NULL;
    if (allowed_libs) {
        /* if setted and not empty, split to list. */
        char *a_libs = strdup(allowed_libs);
        if (strtrim(a_libs) > 0) ns->allowed_libs = strsplit(a_libs,":");
        free(a_libs);
    }
W
wangjiahui 已提交
325
    LD_LOGD("ns_set_allowed_libs ns[%s] allowed_libs:%s.\n", ns->ns_name, allowed_libs);
Y
yangwenjun 已提交
326 327 328 329
}

ns_t *find_ns_by_name(const char *ns_name)
{
W
wangjiahui 已提交
330 331 332 333 334 335 336 337
    if (!ns_name) {
        LD_LOGW("find_ns_by_name failed,ns_name is NULL!\n");
        return NULL;
    }
    if (strcmp(NS_DEFAULT_NAME, ns_name)==0) {
        LD_LOGD("find_ns_by_name return default namespace!\n");
        return get_default_ns();
    }
Y
yangwenjun 已提交
338 339 340 341 342
    for (size_t i=0; i< g_ns_list.num; i++) {
        if (strcmp(g_ns_list.nss[i]->ns_name, ns_name)==0) {
            return g_ns_list.nss[i];
        }
    }
W
wangjiahui 已提交
343
    LD_LOGD("find_ns_by_name ns_name[%s] failed,return NULL!\n", ns_name);
Y
yangwenjun 已提交
344 345 346 347 348
    return NULL;
}

static ns_inherit *find_ns_inherit(ns_t *ns, ns_t *inherited)
{
W
wangjiahui 已提交
349 350 351 352
    if (!ns||!inherited) {
        LD_LOGW("find_ns_inherit failed,ns or inherited is NULL!\n");
        return NULL;
    }
Y
yangwenjun 已提交
353 354 355 356 357
    if (ns->ns_inherits) {
        for (size_t i=0; i<ns->ns_inherits->num; i++) {
            if (ns->ns_inherits->inherits[i]->inherited_ns == inherited) return ns->ns_inherits->inherits[i];
        }
    }
W
wangjiahui 已提交
358
    LD_LOGD("find_ns_inherit ns[%s] ns_inherited[%s] failed,return NULL!\n", ns->ns_name, inherited->ns_name);
Y
yangwenjun 已提交
359 360 361 362 363 364
    return NULL;
}

void ns_add_inherit(ns_t *ns, ns_t *ns_inherited, const char *shared_libs)
{   
    bool need_add = false;
W
wangjiahui 已提交
365 366 367 368
    if (!ns||!ns_inherited) {
        LD_LOGW("ns_add_inherit failed,ns or inherited is NULL!\n");
        return;
    }
Y
yangwenjun 已提交
369 370 371 372

    ns_inherit *inherit = find_ns_inherit(ns, ns_inherited);
    if (!inherit) {
        inherit = calloc(1, sizeof *inherit);
W
wangjiahui 已提交
373 374 375 376
        if (!inherit) {
            LD_LOGW("ns_add_inherit ns[%s] ns_inherited[%s] calloc failed!\n", ns->ns_name, ns_inherited->ns_name);
            return;
        }
Y
yangwenjun 已提交
377 378
        inherit->inherited_ns = ns_inherited;
        need_add = true;
W
wangjiahui 已提交
379
        LD_LOGD("ns_add_inherit ns[%s] ns_inherited[%s] need_add is true.\n", ns->ns_name, ns_inherited->ns_name);
Y
yangwenjun 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393
    }
    
    if (inherit->shared_libs) {
        strlist_free(inherit->shared_libs);
        inherit->shared_libs = NULL;
    }

    /* if setted and not empty, split to list. */
    if (shared_libs) {
        char *s_libs = strdup(shared_libs);
        if (strtrim(s_libs) > 0) inherit->shared_libs = strsplit(shared_libs,":");
        free(s_libs);
    }

W
wangjiahui 已提交
394 395 396 397
    if (!need_add) {
        LD_LOGD("ns_add_inherit ns[%s] ns_inherited[%s] not need_add!\n", ns->ns_name, ns_inherited->ns_name);
        return;
    }
Y
yangwenjun 已提交
398 399 400 401 402 403 404

    if (!ns->ns_inherits) {
        ns->ns_inherits = nsinherits_alloc();
    }

    if (!ns->ns_inherits) {
        if (inherit->shared_libs) strlist_free(inherit->shared_libs);
W
wangjiahui 已提交
405 406
        LD_LOGD("ns_add_inherit ns[%s] ns_inherited[%s] nsinherits_alloc failed!\n",
                ns->ns_name, ns_inherited->ns_name);
Y
yangwenjun 已提交
407 408 409 410 411 412
        free(inherit);
        return;
    }

    if (ns->ns_inherits->num == ns->ns_inherits->size) {
        /* if list is full, realloc size to double*/
W
wangjiahui 已提交
413 414
        LD_LOGD("ns_add_inherit ns[%s] ns_inherited[%s] list is full, realloc size to double!\n",
                ns->ns_name, ns_inherited->ns_name);
Y
yangwenjun 已提交
415 416 417 418 419
        nsinherits_realloc(ns->ns_inherits);
    }

    if (ns->ns_inherits->num < ns->ns_inherits->size) {
        /* realloc succ */
W
wangjiahui 已提交
420
        LD_LOGD("ns_add_inherit ns[%s] ns_inherited[%s] realloc success!\n", ns->ns_name, ns_inherited->ns_name);
Y
yangwenjun 已提交
421 422 423 424
        ns->ns_inherits->inherits[ns->ns_inherits->num] = inherit;
        ns->ns_inherits->num++;
    } else {
        /* realloc failed */
W
wangjiahui 已提交
425
        LD_LOGD("ns_add_inherit ns[%s] ns_inherited[%s] realloc failed!\n", ns->ns_name, ns_inherited->ns_name);
Y
yangwenjun 已提交
426 427 428 429 430 431 432
        if (inherit->shared_libs) strlist_free(inherit->shared_libs);
        free(inherit);
    }
    return;
}

/* check library's pathname if accessible in this namespace */
W
wangjiahui 已提交
433
bool is_accessible(ns_t *ns, const char *lib_pathname, bool is_asan, bool check_inherited)
Y
yangwenjun 已提交
434
{
W
wangjiahui 已提交
435 436
    if (check_inherited && !ns->separated) {
        LD_LOGD("is_accessible ns [%s] is not separated, return true.\n", ns->ns_name);
Y
yangwenjun 已提交
437 438 439 440 441 442 443 444 445 446 447 448
        return true;
    }
    if (ns->allowed_libs) {
        char *shortname = strrchr(lib_pathname, '/');
        if (shortname) {
            shortname += 1;
            size_t i = 0;
            for (; i<ns->allowed_libs->num; i++) {
                if (strcmp(shortname, ns->allowed_libs->strs[i]) == 0) {
                    break;
                }
            }
W
wangjiahui 已提交
449 450 451 452 453
            if (i >= ns->allowed_libs->num) {
                LD_LOGD("is_accessible ns [%s] lib_pathname [%s] is not in allowed_libs, return false.\n",
                        ns->ns_name, lib_pathname);
                return false;
            }
Y
yangwenjun 已提交
454 455 456 457 458 459 460 461 462
        }
    }
    strlist  *paths;
    if (ns->env_paths && (paths = strsplit(ns->env_paths, ":"))) {
        for (size_t i=0; i<paths->num; i++) {
            size_t len = strlen(paths->strs[i]);
            if (strncmp(lib_pathname, paths->strs[i], len) == 0 &&
                lib_pathname[len] == '/' &&
                !strchr(lib_pathname+len +1, '/')) {
W
wangjiahui 已提交
463 464
                LD_LOGD("is_accessible ns [%s] lib_pathname [%s] in env_paths, return true.\n",
                        ns->ns_name, lib_pathname);
Y
yangwenjun 已提交
465 466 467 468 469 470 471
                strlist_free(paths);
                return true;
            }
        }
        strlist_free(paths);
    }

W
wangjiahui 已提交
472 473 474 475 476 477 478 479
    if (is_asan) {
        if (check_asan_path(ns, lib_pathname)) {
            LD_LOGD("is_accessible ns [%s] lib_pathname [%s] check_asan_path success, return true.\n",
                    ns->ns_name, lib_pathname);
            return true;
        }
    }

Y
yangwenjun 已提交
480 481 482 483 484 485 486
    if (ns->lib_paths && (paths = strsplit(ns->lib_paths, ":"))) {
        for (size_t i=0; i<paths->num; i++) {
            size_t len = strlen(paths->strs[i]);
            if (strncmp(lib_pathname, paths->strs[i], len) == 0 &&
                lib_pathname[len] == '/' &&
                !strchr(lib_pathname+len +1, '/')) {
                strlist_free(paths);
W
wangjiahui 已提交
487 488
                LD_LOGD("is_accessible ns [%s] lib_pathname [%s] in lib_paths, return true.\n",
                        ns->ns_name, lib_pathname);
Y
yangwenjun 已提交
489 490 491
                return true;
            } 
        }
W
wangjiahui 已提交
492
        strlist_free(paths);
Y
yangwenjun 已提交
493 494
    }

W
wangjiahui 已提交
495
    if (ns->permitted_paths) {
Y
yangwenjun 已提交
496 497 498 499
        for (size_t i=0; i<ns->permitted_paths->num; i++) {
            size_t len = strlen(ns->permitted_paths->strs[i]);
            if (strncmp(lib_pathname, ns->permitted_paths->strs[i], len) == 0 &&
                lib_pathname[len] == '/') {
W
wangjiahui 已提交
500 501
                LD_LOGD("is_accessible ns [%s] lib_pathname [%s] in permitted_paths, return true.\n",
                        ns->ns_name, lib_pathname);
Y
yangwenjun 已提交
502 503 504 505
                return true;
            }
        }
    }
W
wangjiahui 已提交
506 507
    return false;
}
Y
yangwenjun 已提交
508

W
wangjiahui 已提交
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
bool check_asan_path(ns_t *ns, const char *lib_pathname)
{
    strlist  *paths;
    if (ns->asan_lib_paths && (paths = strsplit(ns->asan_lib_paths, ":"))) {
        for (size_t i = 0; i < paths->num; i++) {
            size_t len = strlen(paths->strs[i]);
            if (strncmp(lib_pathname, paths->strs[i], len) == 0 &&
                lib_pathname[len] == '/' &&
                !strchr(lib_pathname+len +1, '/')) {
                strlist_free(paths);
                LD_LOGD("check_asan_path ns [%s] lib_pathname [%s] in asan_lib_paths, return true.\n",
                        ns->ns_name, lib_pathname);
                return true;
            } 
        }
        strlist_free(paths);
    }
    if (ns->asan_permitted_paths) {
        for (size_t i = 0; i < ns->asan_permitted_paths->num; i++) {
            size_t len = strlen(ns->asan_permitted_paths->strs[i]);
            if (strncmp(lib_pathname, ns->asan_permitted_paths->strs[i], len) == 0 &&
                lib_pathname[len] == '/') {
                LD_LOGD("check_asan_path ns [%s] lib_pathname [%s] in asan_permitted_paths, return true.\n",
                        ns->ns_name,lib_pathname);
                return true;
            }
        }
    }
    LD_LOGD("check_asan_path ns [%s] lib_pathname [%s] failed, return false.\n", ns->ns_name, lib_pathname);
Y
yangwenjun 已提交
538 539 540 541 542 543 544 545
    return false;
}

bool is_sharable(ns_inherit *inherit, const char *lib_name)
{
    if (inherit && lib_name && inherit->shared_libs) {
        for (size_t i=0; i<inherit->shared_libs->num; i++) {
            if (strcmp(inherit->shared_libs->strs[i], lib_name)==0) {
W
wangjiahui 已提交
546
                LD_LOGD("is_sharable inherit [%s] lib_name [%s] found, return true.\n", inherit->inherited_ns->ns_name, lib_name);
Y
yangwenjun 已提交
547 548 549
                return true;
            }
        }
W
wangjiahui 已提交
550
        LD_LOGD("is_sharable inherit [%s] lib_name [%s] not found, return false.\n", inherit->inherited_ns->ns_name, lib_name);
Y
yangwenjun 已提交
551 552
        return false;
    }
W
wangjiahui 已提交
553
     LD_LOGD("is_sharable shared_libs not config, return true.\n");
Y
yangwenjun 已提交
554 555
    return true;
}