|
Lines 358-433
static void strcpy_cw(wchar_t *w, const
Link Here
|
| 358 |
while ((*w++ = *(const nuint8*)s++) != 0); |
358 |
while ((*w++ = *(const nuint8*)s++) != 0); |
| 359 |
} |
359 |
} |
| 360 |
|
360 |
|
| 361 |
NWDSCCODE NWDSCreateContextHandleMnt(NWDSContextHandle* ctx, const NWDSChar * treeName){ |
361 |
NWDSCCODE NWDSSetContextHandleTree(NWDSContextHandle ctx, const NWDSChar * treeName) |
| 362 |
|
362 |
{ |
| 363 |
#define MAXCONNS 64 |
363 |
#define MAXCONNS 64 |
| 364 |
NWDSCCODE err; |
364 |
NWDSCCODE err; |
| 365 |
NWCONN_HANDLE conns[MAXCONNS]; |
365 |
NWCONN_HANDLE conns[MAXCONNS]; |
| 366 |
|
366 |
int curEntries; |
| 367 |
int curEntries=0; |
367 |
int i; |
| 368 |
NWDS_HANDLE dxh; |
368 |
wchar_t treeNameW[MAX_DN_CHARS+1]; |
| 369 |
int i; |
369 |
char treeNameUTF[MAX_DN_CHARS*4 + 1]; |
| 370 |
union __NWDSAuthInfo * ndai; |
370 |
|
| 371 |
size_t authinfo_len; |
371 |
if (!treeName) |
| 372 |
wchar_t wc_treeName[MAX_DN_CHARS+1]; |
372 |
return ERR_NULL_POINTER; |
| 373 |
|
373 |
|
| 374 |
if (!treeName) |
374 |
err = NWDSXlateFromCtx(ctx, treeNameW, sizeof(treeNameW), treeName); |
| 375 |
return ERR_NULL_POINTER; |
375 |
if (err) |
| 376 |
|
376 |
return err; |
| 377 |
strcpy_cw (wc_treeName,treeName); |
377 |
err = iconv_wchar_t_to_external(treeNameW, treeNameUTF, sizeof(treeNameUTF)); |
| 378 |
|
378 |
if (err) |
| 379 |
err=NWDSCreateContextHandle (ctx); |
379 |
return err; |
| 380 |
if (err) |
380 |
err = NWDSSetTreeNameW(ctx, treeNameW); |
| 381 |
return err; |
381 |
if (err) { |
| 382 |
|
382 |
return err; |
| 383 |
err= NWCXGetPermConnListByTreeName (conns,MAXCONNS,&curEntries,getuid(),treeName); |
383 |
} |
| 384 |
if (err) { |
384 |
err = NWCXGetPermConnListByTreeName(conns, MAXCONNS, &curEntries, getuid(), treeNameUTF); |
| 385 |
NWDSFreeContext(*ctx); |
385 |
if (err) { |
| 386 |
return (err); |
386 |
return err; |
| 387 |
} |
387 |
} |
| 388 |
/* printf ("got %d connexion(s) to %s \n",curEntries,treeName);*/ |
388 |
for (i = 0; i < curEntries; i++) { |
| 389 |
dxh=(*ctx)->ds_connection; |
389 |
NWCONN_HANDLE conn = conns[i]; |
| 390 |
if (! dxh){ /* should not be ???*/ |
390 |
err = NWDSAddConnection(ctx, conn); |
| 391 |
NWDSFreeContext(*ctx); |
391 |
if (err) { |
| 392 |
return EINVAL; |
392 |
NWCCCloseConn(conn); |
| 393 |
} |
393 |
continue; |
| 394 |
for (i=0; i <curEntries;i++) { |
394 |
} |
| 395 |
NWCONN_HANDLE conn = conns[i]; |
395 |
} |
| 396 |
err=NWDSAddConnection (*ctx,conn); |
396 |
return 0; |
| 397 |
|
|
|
| 398 |
if (err) { |
| 399 |
/* printf ("error adding connection \n");*/ |
| 400 |
NWCCCloseConn(conn); |
| 401 |
continue; |
| 402 |
} |
| 403 |
if (!dxh->authinfo) { |
| 404 |
/* printf ("trying to get authinfo \n");*/ |
| 405 |
err = ncp_get_private_key(conn, NULL, &authinfo_len); |
| 406 |
if (err) |
| 407 |
continue; /* kernel without private key support */ |
| 408 |
if (!authinfo_len) |
| 409 |
continue; /* no private key on this connection */ |
| 410 |
ndai = (union __NWDSAuthInfo*)malloc(authinfo_len); |
| 411 |
if (!ndai) |
| 412 |
continue; /* not enough memory */ |
| 413 |
err = ncp_get_private_key(conn, ndai, &authinfo_len); |
| 414 |
if (err) { |
| 415 |
free(ndai); |
| 416 |
continue; |
| 417 |
} |
| 418 |
/* printf ("got authinfo \n");*/ |
| 419 |
mlock(ndai, authinfo_len); |
| 420 |
dxh->authinfo = ndai; |
| 421 |
if (dxh->dck.tree_name) |
| 422 |
free(dxh->dck.tree_name); |
| 423 |
dxh->dck.tree_name=wcsdup(wc_treeName); |
| 424 |
} |
| 425 |
|
| 426 |
} |
| 427 |
return 0; |
| 428 |
|
| 429 |
} |
397 |
} |
| 430 |
|
398 |
|
|
|
399 |
NWDSCCODE NWDSCreateContextHandleMnt(NWDSContextHandle* pctx, const NWDSChar * treeName) |
| 400 |
{ |
| 401 |
NWDSCCODE err; |
| 402 |
NWDSContextHandle ctx; |
| 403 |
|
| 404 |
if (!pctx) { |
| 405 |
return ERR_NULL_POINTER; |
| 406 |
} |
| 407 |
err = NWDSCreateContextHandle(&ctx); |
| 408 |
if (err) |
| 409 |
return err; |
| 410 |
err = NWDSSetContextHandleTree(ctx, treeName); |
| 411 |
if (err) |
| 412 |
NWDSFreeContext(ctx); |
| 413 |
else |
| 414 |
*pctx = ctx; |
| 415 |
return err; |
| 416 |
} |
| 431 |
|
417 |
|
| 432 |
//#define NOENV 1 <-- testing reading of .nwinfos file |
418 |
//#define NOENV 1 <-- testing reading of .nwinfos file |
| 433 |
#undef NOENV |
419 |
#undef NOENV |