LCA 可以更新和查询 CA ControlMinder 本地数据库、远程数据库或 PMDB。 管理 API 只能查询本地工作站中的数据库。

下图显示 CA ControlMinder 数据库的布局:

以下示例程序接收命令和(可选)属性名列表作为命令行参数。 程序假定命令为 selang 命令,属性名的显示格式与 dbmgr -d -r p ClassName 命令的显示格式相同(在旧版本 CA ControlMinder 中,与 rdbdump p 命令的显示格式相同)。
该程序调用 lca_ParseLine 函数来执行命令。 执行命令后,对结果进行分析。
如果命令成功,则调用处理查询数据的 API 例程,并显示查询结果。 (如果命令不是查询,则不显示查询信息。)如果提供的是属性列表,则仅显示这些属性的数据。 如果命令失败,则调用分析错误的 API 例程。
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <seostype.h>
#include <langapi.h>
static void scan_entities(void);
static void print_entity_info(LCA_QENT_H entity_handle);
static void scan_props(LCA_QENT_H entity_handle);
static void print_prop_info(LCA_QPROP_H prop_handle);
static void scan_values(LCA_QPROP_H prop_handle);
static void print_prop_value(LCA_QPROP_H prop_handle,void *prop_value);
static char *Command = NULL;
static char **Properties = NULL;
static int NProps = 0;
static void put_commands(int argc,char **argv);
int ShowUsage(void)
{
fprintf( stderr, “Usage:\n
lca_examp Command [{List‑of‑property‑names}]\n”);
return 1;
}
int main(int argc,char **argv)
{
char *output = NULL;
int rv;
int n_ents;
char buff [1025];
/****************** 初始化 ***********************/
/********************************************************/
if ( argc < 2 )
return ShowUsage();
rv = lca_Init(“langapi”,&output);
if ( rv )
{
printf( “Return value: 0x%08x\n”
“Msg: '%s'\n”, rv, output );
return 1;
}
put_commands(‑‑argc,++argv);
/************** 命令执行 **********************/
/********************************************************/
rv = lca_ParseLine(Command, &output);
/* 显示命令输出 */
printf(“Command's output\n%s\n”, output);
if (rv == 0)
{
/************ 成功 ‑ 获取结果 *******************/
/********************************************************/
/** 获取已返回的实体(对象)的数目 ***/
/********************************************************/
n_ents = lca_QEntsGetNum();
printf(“number of entities returned: %d\n”,n_ents);
/******* 获取实体(对象)的名称 *********/
/********************************************************/
scan_entities();
}
else
{
/******************* 命令失败 ******************/
/********************************************************/
LCA_ERR_H error_handle = NULL;
/*********************************************************
* 为了进一步分析错误,请查看所有错误
* (通常只有一个错误,但是如果同时存在警告
* 和错误,则列表中可能有多个错误)。
*********************************************************/
printf(“Numbers of errors: %d\n\n”,lca_ErrsGetNum());
while ((error_handle = lca_ErrGetNext(error_handle))
!= 0)
{
printf(“Severity: %d, Stage:%d\n”,
lca_ErrSeverity(error_handle),
lca_ErrStage (error_handle));
rv = lca_Err2Str (error_handle, buff, sizeof (buff)‑1);
if ( rv )
printf (“Error message: '%s'\n”, buff);
}
}
/************** 终止使用 lca_ API **************/
/********************************************************/
lca_Terminate();
return 0;
}
static void put_commands(int argc,char **argv)
{
Command = argv[0];
Properties = ++argv;
NProps = ‑‑argc;
}
static void scan_entities(void)
{
LCA_QENT_H entity_handle = NULL;
while ( (entity_handle = lca_QEntGetNext(entity_handle)) != 0 )
print_entity_info(entity_handle);
}
/**************************************************************
输出一个实体的信息(包括名称、类名)及其属性信息。
如果实体是一个类,则“名称”为空,“类名”为完整名称。
如果实体是一个对象,则“名称”为完整名称,“类名”为空。
*************************************************************/
static void print_entity_info(LCA_QENT_H entity_handle)
{
char *name;
if ( entity_handle == 0 )
return;
name = lca_QEntObjName(entity_handle);
if ( name != 0 )
printf(“\nName: %s\t”,name);
name = lca_QEntClassName(entity_handle);
if ( name != 0 )
printf(“Class name: %s\n”,name);
scan_props(entity_handle);
}
static void scan_props(LCA_QENT_H entity_handle)
{
LCA_QPROP_H prop_handle = NULL;
register int i;
if ( NProps == 0 )
while ( (prop_handle = lca_QPropGetNext(entity_handle,prop_handle)) != 0)
print_prop_info(prop_handle);
else
for ( i = 0; i < NProps; i++ )
{
prop_handle = lca_QPropGetByName(entity_handle,Properties[i]);
if ( prop_handle == 0 )
{
printf(“Property %s does not exist for this entity.\n”,
Properties[i]);
continue;
}
print_prop_info(prop_handle);
}
}
/*************************************************************
此函数将获取一个属性句柄,以及:
1. 获取其名称并输出该名称。
2. 获取其值,将其转换为字符串,并输出该字符串。
*************************************************************/
static void print_prop_info(LCA_QPROP_H prop_handle)
{
char *prop_name = NULL;
char prop_type;
unsigned short prop_size;
unsigned int n_vals;
if ( prop_handle == 0 )
return;
prop_name = lca_QPropName(prop_handle);
if ( prop_name == 0 )
printf(“Cannot get name of property. Handle: %d\n”,
prop_handle);
printf(“\nPropname: %s.”,prop_name);
prop_type = lca_QPropType(prop_handle);
printf(“Property type: %d; “,prop_type);
prop_size = lca_QPropSize(prop_handle);
printf(“Property size: %d; “,prop_size);
n_vals = lca_QPropValsNum(prop_handle);
printf(“Number of values: %d.\n”,n_vals);
/* 遍历属性值,因为一个属性可能
存在多个值。
如果属性为类型列表(ACL、PACL、用户
列表、成员列表等),则会发生此情况。
*/
scan_values(prop_handle);
}
static void scan_values(LCA_QPROP_H prop_handle)
{
void *prop_value;
int i;
int n_vals;
n_vals = lca_QPropValsNum(prop_handle);
for ( i=0; i<n_vals; i++)
{
prop_value = lca_QPropValGetByIdx(prop_handle,i);
print_prop_value(prop_handle,prop_value);
}
}
static void print_prop_value(LCA_QPROP_H prop_handle,void
*prop_value)
{
char buff[1024];
int n_vals;
if ( prop_handle == 0 || prop_value ==0 )
return;
n_vals= lca_QPropVal2Str(prop_handle,prop_value,buff,sizeof(buff));
if ( n_vals > 0 )
printf(“Value: %s\n”,buff);
}
LCA 包括以下类别的函数:
langapi.h 文件包含每个 LCA 函数的基本说明。 langapi.h 文件位于以下目录:
以下函数控制 LCA 操作:
初始化 LCA。
使用可触发特定功能的特定通讯类型初始化 LCA。
终止 LCA。
执行 selang 命令。
执行 selang 命令并允许输入多字节格式字符串。
连接到一个或多个主机的列表。
以下函数控制 LCA 密码:
检查新密码是否符合密码规则。
以下函数对错误执行操作。 这些错误由执行操作函数造成:
返回最后执行的命令的错误记录数。
针对第 N 个错误记录返回 LCA_ERR_H 类型的错误句柄。
针对命令中的第一个错误返回 LCA_ERR_H 类型的错误句柄。
针对命令中的下一个错误返回 LCA_ERR_H 类型的错误句柄。
返回错误的主要错误代码。
返回错误的次要错误代码。
返回错误的主要错误代码的信息字符串。
返回错误的次要错误代码的信息字符串。
返回错误的重要级别。
返回错误发生时间的相关信息。
将错误记录转换为字符串格式并将其复制到缓冲区。
|
版权所有 © 2013 CA。
保留所有权利。
|
|