static CMPIStatus LMI_NFSElementSettingDataEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { int i; char buf[250]; LMI_NFSElementSettingData n; LMI_NFSElementSettingData_Init(&n, _cb, KNameSpace (cop)); LMI_NFS_ShareRef nfsref; LMI_NFS_ShareRef_Init(&nfsref, _cb, KNameSpace (cop)); LMI_ExportedFileShareSettingRef fileref; LMI_ExportedFileShareSettingRef_Init(&fileref, _cb, KNameSpace (cop)); struct nfs *exportinfo = malloc(sizeof(struct nfs)); exportinfo=get_export_list(); for(i=0;i<exportinfo->countshare;i++) { snprintf(buf, sizeof buf,"%s:%d[of(%d)]", "NFSShare",i+1, exportinfo->countshare); LMI_NFS_ShareRef_Set_InstanceID(&nfsref, buf); snprintf(buf, sizeof buf,"%s:%d[of(%d)]", "NFSExportedFileShareSetting",i+1, exportinfo->countshare); LMI_ExportedFileShareSettingRef_Set_InstanceID(&fileref, buf); LMI_NFSElementSettingData_Set_Share(&n, &nfsref); LMI_NFSElementSettingData_Set_ShareSetting(&n, &fileref); KReturnInstance(cr, n); } CMReturn(CMPI_RC_OK); }
static CMPIStatus LMI_NFS_ShareEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { LMI_NFS_Share s; struct stat st; LMI_NFS_Share_Init(&s, _cb, KNameSpace (cop)); int i; char buf[256]; struct nfs *exportinfo = malloc(sizeof(struct nfs)); exportinfo=get_export_list(); for(i=0;i<exportinfo->countshare;i++) { snprintf(buf, sizeof buf,"%s:%d[of(%d)]", "NFSShare",i+1, exportinfo->countshare); LMI_NFS_Share_Set_InstanceID(&s, buf); LMI_NFS_Share_Set_ElementName(&s, "Nfs Share"); LMI_NFS_Share_Set_Name(&s, exportinfo->share[i]); LMI_NFS_Share_Init_OperationalStatus(&s, 1); if ( stat(exportinfo->share[i], &st) == 0 ) { if(S_ISDIR(st.st_mode)) LMI_NFS_Share_Set_SharingDirectory(&s, 1); else LMI_NFS_Share_Set_SharingDirectory(&s, 0); LMI_NFS_Share_Set_OperationalStatus(&s, 0, 2 ); } else LMI_NFS_Share_Set_OperationalStatus(&s, 0, LMI_NFS_Share_OperationalStatus_Error ); KReturnInstance(cr, s); } CMReturn(CMPI_RC_OK); }
/* usage: listmount server */ int main(int argc, char **argv) { char *hostname; exports exportlist = NULL, exl; groups grouplist; int n; int maxlen; char *wildcard = NULL; program_name = argv[0]; if (argc != 1 && argc != 2 && argc != 3) { printf("USAGE: %s SERVER [MASK]\n", program_name); printf("List all the NFS mounts on SERVER which we are" " allowed to access.\n"); printf("Optional MASK is a mountpoint specification with " "a wildcard (&), ex: /vol/vol1/& will only show " "those mountpoints starting with /vol/vol1\n"); printf("A spec of /vol/vol1/&/foo will show all mountpoints " "starting with /vol/vol1 and ending in /foo\n"); return (1); } hostname = argv[1]; if (argc == 3) wildcard = argv[2]; printf("Export list for %s:\n", hostname); exportlist = get_export_list(hostname); if (wildcard) exportlist = prune_export_list(exportlist, wildcard); maxlen = 0; for (exl = exportlist; exl; exl = exl->ex_next) { if ((n = strlen(exl->ex_dir)) > maxlen) maxlen = n; } while (exportlist) { printf("%-*s ", maxlen, exportlist->ex_dir); grouplist = exportlist->ex_groups; if (grouplist) while (grouplist) { printf("%s%s", grouplist->gr_name, grouplist->gr_next ? "," : ""); grouplist = grouplist->gr_next; } else printf("(everyone)"); printf("\n"); exportlist = exportlist->ex_next; } return (0); }