#include <netinfo/ni.h>
#include <arpa/inet.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include "NiLib2.h"
#include "NiLib3.h"
const char ACCESS_USER_SUPER[] = "root";
const char ACCESS_USER_ANYBODY[] = "*";
const char ACCESS_NAME_PREFIX[] = "_writers_";
const char ACCESS_DIR_KEY[] = "_writers";
ni_status NiLib2::Create ( void *domain, char *pathname )
{
ni_status niStatus;
ni_id dir;
::ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus == NI_OK )
{
return( NI_OK );
}
niStatus = ::ni_root( domain, &dir );
if ( niStatus != NI_OK )
{
return( niStatus );
}
if ( pathname[0] == '/' )
{
niStatus = NiLib2::CreatePath( domain, &dir, pathname + 1 );
}
else
{
niStatus = NiLib2::CreatePath( domain, &dir, pathname );
}
return( niStatus );
}
ni_status NiLib2::CreateProp ( void *domain, char *pathname, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_id dir;
::ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::CreateDirProp( domain, &dir, key, values ) );
}
ni_status NiLib2::CreateDirProp ( void *domain, ni_id *dir, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_property p;
ni_namelist nl;
ni_index where;
::ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
NI_INIT( &p );
p.nip_name = ::ni_name_dup( key );
p.nip_val = ::ni_namelist_dup( values );
niStatus = ::ni_createprop( domain, dir, p, NI_INDEX_NULL );
ni_prop_free( &p );
return( niStatus );
}
niStatus = ::ni_writeprop( domain, dir, where, values );
return( niStatus );
}
ni_status NiLib2::AppendProp ( void *domain, char *pathname, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_id dir;
::ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::AppendDirProp( domain, &dir, key, values ) );
}
ni_status NiLib2::AppendDirProp ( void *domain, ni_id *dir, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_property p;
ni_namelist nl;
ni_index where;
int i;
::ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
NI_INIT( &p );
p.nip_name = ::ni_name_dup( key );
p.nip_val = ::ni_namelist_dup( values );
niStatus = ::ni_createprop( domain, dir, p, NI_INDEX_NULL );
ni_prop_free( &p );
return( niStatus );
}
NI_INIT( &nl );
niStatus = ::ni_readprop( domain, dir, where, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
for ( i = 0; i < (int)values.ni_namelist_len; i++ )
{
ni_namelist_insert( &nl, values.ni_namelist_val[i], NI_INDEX_NULL );
}
niStatus = ::ni_writeprop( domain, dir, where, nl );
::ni_namelist_free( &nl );
return( niStatus );
}
ni_status NiLib2::InsertVal ( void *domain, char *pathname, const ni_name key, const ni_name value, ni_index where )
{
ni_status niStatus;
ni_id dir;
::ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::InsertDirVal( domain, &dir, key, value, where ) );
}
ni_status NiLib2::InsertDirVal ( void *domain,
ni_id *dir,
const ni_name key,
const ni_name value,
ni_index whereval )
{
ni_status niStatus;
ni_property p;
ni_namelist nl;
ni_index where;
::ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
NI_INIT( &nl );
ni_namelist_insert( &nl, value, NI_INDEX_NULL );
NI_INIT( &p );
p.nip_name = ::ni_name_dup( key );
p.nip_val = ::ni_namelist_dup( nl );
niStatus = ::ni_createprop( domain, dir, p, NI_INDEX_NULL );
::ni_namelist_free( &nl );
ni_prop_free( &p );
return( niStatus );
}
NI_INIT( &nl );
niStatus = ::ni_readprop( domain, dir, where, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
ni_namelist_insert( &nl, value, whereval );
niStatus = ::ni_writeprop( domain, dir, where, nl );
::ni_namelist_free( &nl );
return( niStatus );
}
ni_status NiLib2::MergeProp ( void *domain, char *pathname, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_id dir;
::ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return NiLib2::MergeDirProp( domain, &dir, key, values );
}
ni_status NiLib2::MergeDirProp ( void *domain, ni_id *dir, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_property p;
ni_namelist nl;
ni_index where, whereval;
int i;
::ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
NI_INIT( &p );
p.nip_name = ::ni_name_dup( key );
p.nip_val = ::ni_namelist_dup( values );
niStatus = ::ni_createprop( domain, dir, p, NI_INDEX_NULL );
ni_prop_free( &p );
return( niStatus );
}
NI_INIT( &nl );
niStatus = ::ni_readprop( domain, dir, where, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
for ( i = 0; i < (int)values.ni_namelist_len; i++ )
{
whereval = ::ni_namelist_match( nl, values.ni_namelist_val[i] );
if ( whereval == NI_INDEX_NULL )
{
ni_namelist_insert( &nl, values.ni_namelist_val[i], NI_INDEX_NULL );
}
}
niStatus = ::ni_writeprop( domain, dir, where, nl );
::ni_namelist_free( &nl );
return( niStatus );
}
ni_status NiLib2::Destroy ( void *inDomain, ni_id *inDirID )
{
ni_status niStatus;
ni_id parent;
ni_index pi;
::ni_needwrite( inDomain, 1 );
niStatus = ::ni_parent( inDomain, inDirID, &pi );
if ( niStatus != NI_OK )
{
return( niStatus );
}
parent.nii_object = pi;
niStatus = ::ni_self( inDomain, &parent );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::DestroyDir( inDomain, inDirID, &parent ) );
}
ni_status NiLib2::Destroy ( void *domain, char *pathname )
{
ni_status niStatus;
ni_id dir, parent;
ni_index pi;
ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = ::ni_parent( domain, &dir, &pi );
if ( niStatus != NI_OK )
{
return( niStatus );
}
parent.nii_object = pi;
niStatus = ::ni_self( domain, &parent );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::DestroyDir( domain, &dir, &parent ) );
}
ni_status NiLib2::DestroyDir ( void *domain, ni_id *dir, ni_id *parent )
{
ni_status niStatus;
int i;
ni_idlist children;
ni_id child;
ni_needwrite( domain, 1 );
NI_INIT( &children );
niStatus = ::ni_children( domain, dir, &children );
if ( niStatus != NI_OK )
{
return( niStatus );
}
for ( i = 0; i < (int)children.ni_idlist_len; i++ )
{
child.nii_object = children.ni_idlist_val[i];
niStatus = ::ni_self( domain, &child );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = NiLib2::DestroyDir( domain, &child, dir );
if ( niStatus != NI_OK )
{
return( niStatus );
}
}
::ni_idlist_free( &children );
return ::ni_destroy( domain, parent, *dir );
}
ni_status NiLib2::DestroyProp ( void *domain, char *pathname, ni_namelist keys )
{
ni_status niStatus;
ni_id dir;
ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::DestroyDirProp( domain, &dir, keys ) );
}
ni_status NiLib2::DestroyDirProp ( void *domain, ni_id *dir, ni_namelist keys )
{
ni_status niStatus;
ni_index where;
ni_namelist nl;
int i;
ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
for ( i = 0; i < (int)keys.ni_namelist_len; i++ )
{
where = ::ni_namelist_match( nl, keys.ni_namelist_val[i] );
while ( where != NI_INDEX_NULL )
{
niStatus = ::ni_destroyprop( domain, dir, where );
if ( niStatus != NI_OK )
{
::ni_namelist_free( &nl );
return( niStatus );
}
::ni_namelist_delete( &nl, where );
where = ::ni_namelist_match( nl, keys.ni_namelist_val[i] );
}
}
::ni_namelist_free( &nl );
return( NI_OK );
}
ni_status NiLib2::DestroyVal( void *domain, char *pathname, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_id dir;
ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return NiLib2::DestroyDirVal( domain, &dir, key, values );
}
ni_status NiLib2::DestroyDirVal ( void *domain, ni_id *dir, const ni_name key, ni_namelist values )
{
ni_status niStatus;
ni_namelist nl;
ni_index where, whereval;
int i;
ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
return( NI_OK );
}
NI_INIT( &nl );
niStatus = ::ni_readprop( domain, dir, where, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
for ( i = 0; i < (int)values.ni_namelist_len; i++ )
{
whereval = ::ni_namelist_match( nl, values.ni_namelist_val[i] );
while ( whereval != NI_INDEX_NULL )
{
::ni_namelist_delete( &nl, whereval );
whereval = ::ni_namelist_match( nl, values.ni_namelist_val[i] );
}
}
niStatus = ::ni_writeprop( domain, dir, where, nl );
::ni_namelist_free( &nl );
return( niStatus );
}
ni_status NiLib2::RenameProp ( void *domain, char *pathname, const ni_name oldname, const ni_name newname )
{
ni_status niStatus;
ni_id dir;
::ni_needwrite( domain, 1 );
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::RenameDirProp( domain, &dir, oldname, newname ) );
}
ni_status NiLib2::RenameDirProp ( void *domain, ni_id *dir, const ni_name oldname, const ni_name newname )
{
ni_status niStatus;
ni_index where;
ni_namelist nl;
::ni_needwrite( domain, 1 );
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, oldname );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
return NI_NOPROP;
}
return( ::ni_renameprop( domain, dir, where, newname ) );
}
ni_status NiLib2::PathSearch( void *domain, ni_id *dir, char *pathname )
{
int i, len;
bool is_id;
len = strlen( pathname );
is_id = true;
for ( i = 0; i < len && is_id; i++ )
if ( !isdigit( pathname[i] ) ) is_id = false;
if ( is_id )
{
char *endPtr = NULL;
dir->nii_object = ( unsigned long )strtol( pathname, &endPtr, 10 );
return( ::ni_self( domain, dir ) );
}
else
{
return( ::ni_pathsearch( domain, dir, pathname ) );
}
}
ni_status NiLib2::CreatePath ( void *domain, ni_id *dir, char *pathname )
{
ni_status niStatus;
ni_id checkdir;
int i, j, len;
char *dirname = NULL;
bool simple;
i = 0;
while ( pathname[i] != '\0' )
{
simple = true;
for ( j = i; pathname[j] != '\0' && simple; j++ )
{
if ( pathname[j] == '\\' && pathname[j+1] == '/' ) j+=2;
if ( pathname[j] == '/' ) simple = false;
}
len = j - i;
if ( !simple ) len--;
dirname = (char *)::malloc( len + 1 );
strncpy( dirname, pathname+i, len );
dirname[len] = '\0';
i = j;
checkdir = *dir;
niStatus = ::ni_pathsearch( domain, dir, dirname );
if ( niStatus == NI_NODIR )
{
*dir = checkdir;
niStatus = NiLib2::CreateChild( domain, dir, dirname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
}
free( dirname );
}
return( NI_OK );
}
ni_status NiLib2::CreateChild ( void *domain, ni_id *dir, const ni_name dirname )
{
ni_status niStatus;
ni_proplist p;
ni_id child;
int i, j, k, len;
char *key = NULL;
char *value = NULL;
len = 0;
for ( i = 0; dirname[i] != '\0' && dirname[i] != '='; i++ )
;
if ( dirname[i] == '=' )
{
len = i;
}
if ( len > 0 )
{
key = (char *)::malloc( len + 1 );
for ( i = 0, j = 0; i < len; i++, j++ )
{
if ( dirname[i] == '\\' && dirname[i+1] == '/' ) i++;
key[j] = dirname[i];
}
key[j] = '\0';
i = len + 1;
}
else
{
key = (char *)::malloc( 5 );
strcpy( key, "name" );
i = 0;
}
j = strlen( dirname );
len = j - i;
value = (char *)::malloc( len + 1 );
for ( k = 0; i < j; k++, i++ )
{
if ( dirname[i] == '\\' && dirname[i+1] == '/' )
{
i++;
}
value[k] = dirname[i];
}
value[k] = '\0';
NI_INIT( &p );
NiLib3::AppendProp( &p, key, value );
niStatus = ::ni_create( domain, dir, p, &child, NI_INDEX_NULL );
if ( niStatus == NI_OK )
{
*dir = child;
}
ni_proplist_free( &p );
free( key );
free( value );
return( niStatus );
}
ni_status NiLib2::StatProp ( void *domain, char *pathname, const ni_name key, ni_index *where )
{
ni_status niStatus;
ni_id dir;
*where = NI_INDEX_NULL;
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::StatPropDir( domain, &dir, key, where ) );
}
ni_status NiLib2::StatPropDir ( void *domain, ni_id *dir, const ni_name key, ni_index *where )
{
ni_status niStatus;
ni_namelist nl;
*where = NI_INDEX_NULL;
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
*where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( *where == NI_INDEX_NULL )
{
return NI_NOPROP;
}
return( NI_OK );
}
ni_status NiLib2::StatVal ( void *domain, char *pathname, const ni_name key, const ni_name value, ni_index *where )
{
ni_status niStatus;
ni_id dir;
*where = NI_INDEX_NULL;
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::StatValDir( domain, &dir, key, value, where ) );
}
ni_status NiLib2::StatValDir ( void *domain, ni_id *dir, const ni_name key, const ni_name value, ni_index *where )
{
ni_status niStatus;
ni_namelist nl;
ni_index wh;
*where = NI_INDEX_NULL;
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
wh = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( wh == NI_INDEX_NULL )
{
return NI_NOPROP;
}
NI_INIT( &nl );
niStatus = ::ni_readprop( domain, dir, wh, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
wh = ::ni_namelist_match( nl, value );
::ni_namelist_free( &nl );
if ( wh == NI_INDEX_NULL )
{
return NI_NONAME;
}
*where = wh;
return( NI_OK );
}
ni_status NiLib2::ReapProp ( void *domain, char *pathname, const ni_name key )
{
ni_status niStatus;
ni_id dir;
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( NiLib2::ReappropDir( domain, &dir, key ) );
}
ni_status NiLib2::ReappropDir ( void *domain, ni_id *dir, const ni_name key )
{
ni_status niStatus;
ni_namelist nl;
ni_index where;
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
where = ::ni_namelist_match( nl, key );
::ni_namelist_free( &nl );
if ( where == NI_INDEX_NULL )
{
return( NI_OK );
}
NI_INIT( &nl );
niStatus = ::ni_readprop( domain, dir, where, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
if ( nl.ni_namelist_len > 0 )
{
::ni_namelist_free( &nl );
return( NI_OK );
}
::ni_namelist_free( &nl );
return( ::ni_destroyprop( domain, dir, where ) );
}
ni_status NiLib2::ReapDir ( void *domain, char *pathname )
{
ni_status niStatus;
ni_id dir;
ni_namelist nl;
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
NI_INIT( &nl );
niStatus = ::ni_listprops( domain, &dir, &nl );
if ( niStatus != NI_OK )
{
return( niStatus );
}
if ( nl.ni_namelist_len > 1 )
{
::ni_namelist_free( &nl );
return( NI_OK );
}
::ni_namelist_free( &nl );
return( NiLib2::Destroy( domain, pathname ) );
}
ni_status NiLib2::Copy ( void *srcdomain, char *path, void *dstdomain, bool recursive )
{
ni_status niStatus;
ni_id srcdir;
ni_id dstdir;
niStatus = NiLib2::PathSearch( srcdomain, &srcdir, path );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = NiLib2::Create( dstdomain, path );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = NiLib2::PathSearch( dstdomain, &dstdir, path );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = NiLib2::CopyDir( srcdomain, &srcdir, dstdomain, &dstdir, recursive );
return( niStatus );
}
ni_status NiLib2::Copy ( void *srcdomain, ni_id *inSrcDirID, char *path, void *dstdomain, bool recursive )
{
ni_status niStatus;
ni_id dstdir;
niStatus = NiLib2::Create( dstdomain, path );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = NiLib2::PathSearch( dstdomain, &dstdir, path );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = NiLib2::CopyDir( srcdomain, inSrcDirID, dstdomain, &dstdir, recursive );
return( niStatus );
}
ni_status NiLib2::CopyDir ( void *srcdomain, ni_id *srcdir, void *dstdomain, ni_id *dstdir , bool recursive )
{
ni_status niStatus;
ni_idlist children;
int i;
int len;
ni_proplist p;
ni_id dir;
NI_INIT( &p );
niStatus = ::ni_read( srcdomain, srcdir, &p );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = ::ni_write( dstdomain, dstdir, p );
if ( niStatus != NI_OK )
{
ni_proplist_free( &p );
return( niStatus );
}
ni_proplist_free( &p );
if ( recursive )
{
NI_INIT( &children );
niStatus = ::ni_children( srcdomain, srcdir, &children );
if ( niStatus != NI_OK )
{
return( niStatus );
}
len = children.ni_idlist_len;
for ( i = 0; i < len; i++ )
{
dir.nii_object = children.ni_idlist_val[i];
niStatus = ::ni_self( srcdomain, &dir );
if ( niStatus != NI_OK )
{
::ni_idlist_free( &children );
return( niStatus );
}
niStatus = NiLib2::CopyDirToParentDir( srcdomain,&dir,dstdomain,dstdir,recursive );
}
::ni_idlist_free( &children );
}
return( NI_OK );
}
ni_status NiLib2::CopyDirToParentDir ( void *srcdomain, ni_id *srcdir, void*dstdomain, ni_id *dstdir , bool recursive )
{
ni_status niStatus;
ni_idlist children;
int i, len;
ni_proplist p;
ni_id dir, newdstdir;
NI_INIT( &p );
niStatus = ::ni_read( srcdomain, srcdir, &p );
if ( niStatus != NI_OK )
{
return( niStatus );
}
niStatus = ::ni_create( dstdomain, dstdir, p, &newdstdir, NI_INDEX_NULL );
if ( niStatus != NI_OK )
{
ni_proplist_free( &p );
return( niStatus );
}
ni_proplist_free( &p );
if ( recursive )
{
NI_INIT( &children );
niStatus = ::ni_children( srcdomain, srcdir, &children );
if ( niStatus != NI_OK )
{
return( niStatus );
}
len = children.ni_idlist_len;
for ( i = 0; i < len; i++ )
{
dir.nii_object = children.ni_idlist_val[i];
niStatus = ::ni_self( srcdomain, &dir );
if ( niStatus != NI_OK )
{
::ni_idlist_free( &children );
return( niStatus );
}
niStatus = NiLib2::CopyDirToParentDir( srcdomain,&dir,dstdomain, &newdstdir,recursive );
}
::ni_idlist_free( &children );
}
return( NI_OK );
}
ni_status NiLib2::LookUpProp ( void *domain, char *pathname, const ni_name key, ni_namelist *values )
{
ni_status niStatus;
ni_id dir;
niStatus = NiLib2::PathSearch( domain, &dir, pathname );
if ( niStatus != NI_OK )
{
return( niStatus );
}
return( ::ni_lookupprop( domain, &dir, key, values ) );
}
ni_index NiLib2::InsertSorted ( ni_namelist *values, const ni_name newvalue )
{
int i, len;
len = values->ni_namelist_len;
for ( i = 0; i < len; i++ )
{
if ( strcmp( newvalue, values->ni_namelist_val[i] ) <= 0 )
{
ni_namelist_insert( values, newvalue, ( ni_index )i );
return ( ni_index )i;
}
}
ni_namelist_insert( values, newvalue, NI_INDEX_NULL );
return( NI_INDEX_NULL );
}
ni_status NiLib2::InAccessList( const char* user, ni_namelist access_list)
{
if (ni_namelist_match(access_list, ACCESS_USER_ANYBODY) != NI_INDEX_NULL)
{
return NI_OK;
}
if (user == NULL || user[0] == '\0')
{
return NI_PERM;
}
if (ni_namelist_match(access_list, user) != NI_INDEX_NULL)
{
return NI_OK;
}
return NI_PERM;
}
ni_status NiLib2::ValidateDir( const char* user, ni_proplist *pl )
{
ni_index i;
if ((user != NULL) && (strcmp(user, ACCESS_USER_SUPER) == 0))
{
return NI_OK;
}
for (i = 0; i < pl->nipl_len; i++)
{
if (strcmp(pl->nipl_val[i].nip_name, ACCESS_DIR_KEY) == 0)
{
return NiLib2::InAccessList(user, pl->nipl_val[i].nip_val);
}
}
return NI_PERM;
}
ni_status NiLib2::ValidateName( const char* user, ni_proplist *pl, ni_index prop_index )
{
ni_name key = NULL;
ni_name propkey;
ni_index i;
if ((user != NULL) && (ni_name_match(user, ACCESS_USER_SUPER)))
{
return NI_OK;
}
if ( prop_index == NI_INDEX_NULL )
return NI_OK;
propkey = pl->nipl_val[prop_index].nip_name;
if (propkey == NULL)
{
return NI_PERM;
}
key = (char*)::calloc(strlen(ACCESS_NAME_PREFIX) + strlen(propkey) + 1, 1);
sprintf(key, "%s%s", ACCESS_NAME_PREFIX, propkey);
for (i = 0; i < pl->nipl_len; i++)
{
if (ni_name_match(pl->nipl_val[i].nip_name, key))
{
ni_name_free(&key);
return NiLib2::InAccessList(user, pl->nipl_val[i].nip_val);
}
}
ni_name_free(&key);
return NI_PERM;
}