NISPlus
view release on metacpan or search on metacpan
if ((sv = hv_fetch(hdata, "ta_sep", 6, FALSE)) != (SV **)NULL)
object->TA_data.ta_sep = *SvPV(*sv, na);
if ((sv = hv_fetch(hdata, "ta_cols", 7, FALSE)) != (SV **)NULL)
{
cols = (AV *)SvRV(*sv);
if (av_len(cols)+1 != object->TA_data.ta_maxcol)
croak("number of columns in ta_cols %d must match table %d\n",
av_len(cols)+1, object->TA_data.ta_maxcol);
}
if ((sv = hv_fetch(hdata, "ta_cols_flags", 13, FALSE)) != (SV **)NULL)
colflags = (HV *)SvRV(*sv);
if ((sv = hv_fetch(hdata, "ta_cols_rights", 14, FALSE)) !=(SV **)NULL)
colrights = (HV *)SvRV(*sv);
for (col=0; col<object->TA_data.ta_cols.ta_cols_len; col++)
{
if (cols)
object->TA_data.ta_cols.ta_cols_val[col].tc_name =
strdup(SvPV(*av_fetch(cols, col, 0), na));
colname = object->TA_data.ta_cols.ta_cols_val[col].tc_name;
if (colrights &&
(sv = hv_fetch(colrights, colname, strlen(colname), FALSE))
!= (SV **)NULL)
object->TA_data.ta_cols.ta_cols_val[col].tc_rights = SvIV(*sv);
if (colflags &&
(sv = hv_fetch(colflags, colname, strlen(colname), FALSE))
!= (SV **)NULL)
object->TA_data.ta_cols.ta_cols_val[col].tc_flags = SvIV(*sv);
}
if ((sv = hv_fetch(hdata, "ta_path", 7, FALSE)) != (SV **)NULL)
object->TA_data.ta_path = strdup(SvPV(*sv, na));
break;
}
case ENTRY_OBJ:
break;
case LINK_OBJ:
break;
case PRIVATE_OBJ:
break;
default:
break;
}
return;
}
MODULE = Net::NISPlus PACKAGE = Net::NISPlus
# for returning C constants to Perl
double
constant(name,arg)
char * name
int arg
# the following functions are direct implementations of nis functions.
# see the manual pages on these functions for a description of what they do
void
nis_getnames(name)
nis_name name
PPCODE:
{
nis_name * names;
nis_name * names_first;
names_first = names = nis_getnames(name);
while(*names != NULL)
{
XPUSHs(sv_2mortal(newSVpv(*names, 0)));
names++;
}
nis_freenames(names_first);
}
nis_name
nis_leaf_of(name)
nis_name name
nis_name
nis_name_of(name)
nis_name name
nis_name
nis_domain_of(name)
nis_name name
name_pos
nis_dir_cmp(name1, name2)
nis_name name1
nis_name name2
nis_name
nis_local_directory()
nis_name
nis_local_host()
nis_name
nis_local_group()
nis_name
nis_local_principal()
bool_t
nis_ismember(name1, name2)
nis_name name1
nis_name name2
void
nis_add(name, owner, group, access, ttl, type, sep, path, data)
nis_name name
nis_name owner
nis_name group
unsigned long access
unsigned long ttl
char * type
unsigned char sep
char * path
SV * data
PPCODE:
{
nis_object object;
nis_result *res;
int pos;
SV **val;
object.zo_name = "";
object.zo_owner = owner;
object.zo_group = group;
object.zo_domain = "";
object.zo_access = access;
object.zo_ttl = ttl;
object.zo_data.zo_type = TABLE_OBJ;
object.TA_data.ta_type = type;
object.TA_data.ta_sep = sep;
object.TA_data.ta_path = path;
object.TA_data.ta_maxcol = av_len((AV *)SvRV(data))+1;
object.TA_data.ta_cols.ta_cols_len = object.TA_data.ta_maxcol;
if ((object.TA_data.ta_cols.ta_cols_val =
(table_col *)malloc(sizeof(table_col) *
object.TA_data.ta_cols.ta_cols_len)) == (table_col *)NULL)
{
croak("can't allocate memory for ta_data");
}
for (pos=0; pos<object.TA_data.ta_maxcol; pos++)
{
val = av_fetch((AV *)SvRV(data), pos, 0);
if (val != (SV **)NULL && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV)
{
unsigned long flags;
unsigned long rights;
object.TA_data.ta_cols.ta_cols_val[pos].tc_name =
SvPV(*av_fetch((AV *)SvRV(*val), 0, 0), na);
object.TA_data.ta_cols.ta_cols_val[pos].tc_flags =
SvNV(*av_fetch((AV *)SvRV(*val), 1, 0));
object.TA_data.ta_cols.ta_cols_val[pos].tc_rights =
SvNV(*av_fetch((AV *)SvRV(*val), 2, 0));
}
else
{
croak("nis_add: invalid data\n");
}
}
if ((res = nis_add(name, &object)) == (nis_result *)NULL)
XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res->status)));
nis_freeresult(res);
}
}
void
nis_add_entry(name, data, owner, group, access, ttl)
nis_name name
SV * data
nis_name owner
nis_name group
unsigned long access
unsigned long ttl
PPCODE:
{
nis_result *table;
nis_result *res;
nis_object entry;
table = lookup(name);
if (table == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
fill_entry(table, &entry, data, 1);
entry.zo_name = "";
entry.zo_owner = owner;
entry.zo_group = group;
entry.zo_domain = "";
entry.zo_access = access;
if (ttl == 0) ttl = NIS_RES_OBJECT(table)[0].zo_ttl;
entry.zo_ttl = ttl;
if ((res = nis_add_entry(name, &entry, 0)) == (nis_result *)NULL)
XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res->status)));
nis_freeresult(res);
}
free_entry(&entry, 1);
nis_freeresult(table);
}
}
void
nis_remove_entry(name, flags)
nis_name name
unsigned long flags
PPCODE:
{
nis_result *res;
if ((res = nis_remove_entry(name, (nis_object *)NULL, flags)) ==
(nis_result *)NULL)
XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res->status)));
nis_freeresult(res);
}
}
void
nis_modify_entry(name, data, flags)
nis_name name
SV * data
unsigned long flags
PPCODE:
{
nis_result *table;
nis_result *res, *lres;
nis_object *entry;
nis_name tname;
int num;
# first, we get a reference to the table object. This is used for
# the column names for fill_entry()
if ((tname = (nis_name)strrchr((char *)name, ',')) == (char *)NULL)
tname = name;
else tname++;
table = lookup(tname);
if (table == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
# next, we grab a list of entries which match the search pattern
lres=nis_list(name, 0, (int(*)())NULL, (void *)NULL);
if (lres == (nis_result *)NULL)
{
croak("nis_list returned NULL");
}
if (!lres->status)
{
# now we enumerate over the entries, changing the fields which changed
for (num=0; num<NIS_RES_NUMOBJ(lres); num++)
{
if (NIS_RES_OBJECT(lres)[num].zo_data.zo_type != ENTRY_OBJ)
{
croak("not an entry object in nis_modify_entry");
}
entry = &NIS_RES_OBJECT(lres)[num];
fill_entry(table, entry, data, 0);
if ((res = nis_modify_entry(name, entry, flags)) == (nis_result *)NULL)
XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res->status)));
nis_freeresult(res);
}
# come back to this one XXX
#if 0
free_entry(&entry, 0);
#endif
}
}
else
{
warn("nis_modify_entry:status returned from nis_list = %d\n", lres->status);
}
nis_freeresult(lres);
}
nis_freeresult(table);
}
# list the names of the table entries
void
name_list(name)
nis_name name
PPCODE:
{
nis_result *res;
res = nis_list(name, 0, (int(*)())NULL, (void *)NULL);
if (res == (nis_result *)NULL)
{
croak("nis_list returned NULL");
}
XPUSHs(sv_2mortal(newSViv(res->status)));
if (!res->status)
{
NISRESULT_NAMES(res);
}
nis_freeresult(res);
}
# return an array of the contents of the table entries
void
entry_list(name, tableref)
nis_name name
SV * tableref
PPCODE:
{
nis_result *res;
res=nis_list(name, MASTER_ONLY, (int(*)())NULL, (void *)NULL);
if (res == (nis_result *)NULL)
{
croak("nis_list returned NULL");
}
XPUSHs(sv_2mortal(newSViv(res->status)));
if (!res->status)
{
NISRESULT_ENTRY(res, tableref);
}
nis_freeresult(res);
}
void
nis_first_entry(name)
nis_name name
PPCODE:
{
nis_result *res;
u_int num;
res=nis_first_entry(name);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res->status)));
if (!res->status)
{
XPUSHs(sv_2mortal(newSVpv(res->cookie.n_bytes, res->cookie.n_len)));
NISRESULT_ENTRY(res, &sv_undef);
}
nis_freeresult(res);
}
}
void
nis_next_entry(name, cookie)
nis_name name
netobj cookie
PPCODE:
{
nis_result *res;
u_int num;
res=nis_next_entry(name, &cookie);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res->status)));
if (!res->status)
{
XPUSHs(sv_2mortal(newSVpv(res->cookie.n_bytes, res->cookie.n_len)));
NISRESULT_ENTRY(res, &sv_undef);
}
nis_freeresult(res);
}
}
char *
nis_sperrno(status)
nis_error status
void
nis_perror(status, label)
nis_error status
char * label
void
nis_lerror(status, label)
nis_error status
char * label
# return information about an entry object
void
entry_info(path)
nis_name path
PPCODE:
{
nis_result *res;
res = lookup(path);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
HV *hv;
XPUSHs(sv_2mortal(newSViv(res->status)));
XPUSHs(sv_2mortal(newRV((SV *) (hv = nisresult_info(res)))));
sv_free((SV *) hv);
nis_freeresult(res);
}
}
# return information about a table object
void
table_info(path)
nis_name path
PPCODE:
{
nis_result *res;
res = lookup(path);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
HV *hv;
XPUSHs(sv_2mortal(newSViv(res->status)));
XPUSHs(sv_2mortal(newRV((SV *) (hv = nisresult_info(res)))));
sv_free((SV *) hv);
nis_freeresult(res);
}
}
# set information in an entry object
void
entry_setinfo(name, data)
nis_name name
SV * data
PPCODE:
{
nis_result *res, *res2;
res = nis_list(name, MASTER_ONLY, (int(*)())NULL, (void *)NULL);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
setinfo(data, NIS_RES_OBJECT(res));
if ((res2 = nis_modify_entry(name, NIS_RES_OBJECT(res), MOD_SAMEOBJ))
== (nis_result *)NULL)
XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res2->status)));
nis_freeresult(res2);
}
nis_freeresult(res);
}
}
# set information in a table object
void
table_setinfo(path, data)
nis_name path
SV * data
PPCODE:
{
nis_result *res, *res2;
SV **sv;
res = lookup(path);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
setinfo(data, NIS_RES_OBJECT(res));
if ((res2 = nis_modify(path, NIS_RES_OBJECT(res))) == (nis_result *)NULL)
XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(res2->status)));
nis_freeresult(res2);
}
nis_freeresult(res);
}
}
# return the type of an object (e.g. TABLE, ENTRY, etc)
void
obj_type(path)
nis_name path
PPCODE:
{
nis_result *res;
res = lookup(path);
if (res == (nis_result *)NULL) XPUSHs(sv_newmortal());
else
{
XPUSHs(sv_2mortal(newSViv(NIS_RES_OBJECT(res)[0].zo_data.zo_type)));
nis_freeresult(res);
}
}
( run in 0.563 second using v1.01-cache-2.11-cpan-5511b514fd6 )