%% options copyright owner = Dirk Krause copyright year = 2012-2014 license = bsd %% module #include "dk3all.h" #include "itadmin.h" $!trace-include /** Keywords used by the module. */ static char const * const itadmin_netgroup_c8_kw[] = { $!string-table # # 0: File name "netgroup.ldif" # netgroup.ldif # # 1: File open mode "w" # w # # 2: Start of DN line # dn: cn= # # 3: Middle of DN line # ,ou=netgroup, # # 4: objectClass: top # objectClass: top # # 5: objectClass: nisNetgroup # objectClass: nisNetgroup # # 6: cn: (start of line) # cn: # # 7: nisNetgroupTriple: (start of line) # nisNetgroupTriple: ( # # 8: Center of nisNetgroupTriple line # ,, # # 9: End of nisNetgroupTriple line # ) $!end }; int itadmin_netgroup_expand(itadmin_job *job) { itadmin_netgroup *ng; /* Current netgroup. */ itadmin_ngdep *nd; /* Netgroup dependency. */ size_t nng; /* Next netgroup number. */ int back = 0; $? "+ itadmin_netgroup_expand" /* Assign number to each netgroup. */ nng = 0; dk3sto_it_reset(job->i_ng); while(NULL != (ng = (itadmin_netgroup *)dk3sto_it_next(job->i_ng))) { ng->no = nng++; } job->nng = nng; /* Create dependency matrix. */ if(nng > 0) { job->ngdep = dk3bm_open(nng, nng, job->app); if(job->ngdep) { $? ". allocation" /* Enter dependencies into matrix. */ dk3sto_it_reset(job->i_nd); while(NULL != (nd = (itadmin_ngdep *)dk3sto_it_next(job->i_nd))) { if((nd->ch) && (nd->pa)) { dk3bm_set(job->ngdep, (nd->ch)->no, (nd->pa)->no, 1); } } /* Expand matrix to find indirect parent/child relations. */ dk3bm_expand(job->ngdep); back = 1; } else { $? "! allocation" } } else { $? ". no netgroups" back = 1; } $? "- itadmin_netgroup_expand %d", back return back; } int itadmin_netgroup_host_member( itadmin_job *job, itadmin_netgroup *netgroup, itadmin_host *host ) { int back = 0; $? "+ itadmin_netgroup_host_member" if((netgroup) && (host)) { $? ". args ok" if(host->ng) { $? ". host->ng" if((host->ng)->no == netgroup->no) { $? ". direct" back = 2; } else { $? ". not direct" if(job->ngdep) { $? ". job->ngdep" if(dk3bm_get(job->ngdep, (host->ng)->no, netgroup->no)) { back = 1; } } else { $? "! job->ngdep" } } } else { $? ". no primary ng" } } else { $? "! args" } $? "- itadmin_netgroup_host_member %d", back return back; } int itadmin_netgroup_ldif_output(itadmin_job *job) { char bu[ITADMIN_CONFIG_LINE_SIZE]; itadmin_netgroup *ng; /* Current netgroup to process. */ itadmin_host *host; /* Current host to process. */ FILE *fipo; /* Output file. */ char const *al; /* Current alias name. */ int ie; /* Input encoding. */ int nghf = 0; /* Flag: Already host found here. */ int back = 0; $? "+ itadmin_netgroup_ldif_output" ie = dk3app_get_encoding(job->app); if(dk3str_to_c8u_app(bu,sizeof(bu),job->ldapb,ie,job->app)) { $? ". bu" fipo = dk3sf_c8_fopen_app( itadmin_netgroup_c8_kw[0], itadmin_netgroup_c8_kw[1], job->app ); if(fipo) { $? ". fipo" dk3sto_it_reset(job->i_ng); while(NULL != (ng = (itadmin_netgroup *)dk3sto_it_next(job->i_ng))) { nghf = 0; $? ". ng" dk3sto_it_reset(job->i_hoi); while(NULL != (host = (itadmin_host *)dk3sto_it_next(job->i_hoi))) { if((host->sn) && (host->ipv4) && (host->dnsd)) { $? ". host" if(itadmin_netgroup_host_member(job, ng, host)) { $? ". member" if(!(nghf)) { fputs(itadmin_netgroup_c8_kw[2], fipo); fputs(ng->sn, fipo); fputs(itadmin_netgroup_c8_kw[3], fipo); fputs(bu, fipo); fputc('\n', fipo); fputs(itadmin_netgroup_c8_kw[4], fipo); fputc('\n', fipo); fputs(itadmin_netgroup_c8_kw[5], fipo); fputc('\n', fipo); fputs(itadmin_netgroup_c8_kw[6], fipo); fputs(ng->sn, fipo); fputc('\n', fipo); } nghf = 1; $? ". header ok" /* Short host name */ fputs(itadmin_netgroup_c8_kw[7], fipo); fputs(host->sn, fipo); fputs(itadmin_netgroup_c8_kw[8], fipo); fputs(host->dnsd, fipo); fputs(itadmin_netgroup_c8_kw[9], fipo); fputc('\n', fipo); /* Full host name */ fputs(itadmin_netgroup_c8_kw[7], fipo); fputs(host->sn, fipo); fputc('.', fipo); fputs(host->dnsd, fipo); fputs(itadmin_netgroup_c8_kw[8], fipo); fputs(host->dnsd, fipo); fputs(itadmin_netgroup_c8_kw[9], fipo); fputc('\n', fipo); /* Aliases */ if(host->i_al) { dk3sto_it_reset(host->i_al); while(NULL != (al = (char const *)dk3sto_it_next(host->i_al))) { fputs(itadmin_netgroup_c8_kw[7], fipo); fputs(al, fipo); fputs(itadmin_netgroup_c8_kw[8], fipo); fputs(host->dnsd, fipo); fputs(itadmin_netgroup_c8_kw[9], fipo); fputc('\n', fipo); } } /* IP */ fputs(itadmin_netgroup_c8_kw[7], fipo); itadmin_tool_write_ip(fipo, host->ipv4); fputs(itadmin_netgroup_c8_kw[8], fipo); fputs(host->dnsd, fipo); fputs(itadmin_netgroup_c8_kw[9], fipo); fputc('\n', fipo); } else { $? ". no member" } } } if(nghf) { fputc('\n', fipo); } } back = 1; #if DK3_CHAR_SIZE == 1 if(!dk3sf_fclose_fn_app(fipo, itadmin_netgroup_c8_kw[0], job->app)) { back = 0; } #else if(!dk3sf_fclose_fn_app(fipo, NULL, job->app)) { back = 0; } #endif } else { $? "! fipo" } } else { $? "! bu" } $? "- itadmin_netgroup_ldif_output %d", back return back; }