From e097666499564ffe28836876a7a191149c14f199 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 12 Feb 2002 18:22:47 +0000 Subject: [PATCH] talloc'ify ads modify functions. --- source/libads/ldap_printer.c | 86 +++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/source/libads/ldap_printer.c b/source/libads/ldap_printer.c index 50f43022016..52771ba39a4 100644 --- a/source/libads/ldap_printer.c +++ b/source/libads/ldap_printer.c @@ -45,7 +45,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, asprintf(&exp, "(printerName=%s)", printer); status = ads_do_search(ads, srv_dn, LDAP_SCOPE_SUBTREE, - exp, &attrs, res); + exp, attrs, res); free(exp); return status; @@ -57,46 +57,51 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, const ADS_PRINTER_ENTRY *prt) { - ADS_MODLIST *mods; + ADS_MODLIST mods; ADS_STATUS status; + TALLOC_CTX *ctx; + + if (!(ctx = talloc_init_named("mod_printer_entry"))) + return ADS_ERROR(LDAP_NO_MEMORY); /* allocate the list */ - *mods = ads_init_mods(); + mods = ads_init_mods(ctx); /* add the attributes to the list - required ones first */ - ads_mod_repl(mods, "printerName", prt->printerName); - ads_mod_repl(mods, "serverName", prt->serverName); - ads_mod_repl(mods, "shortServerName", prt->shortServerName); - ads_mod_repl(mods, "uNCName", prt->uNCName); - ads_mod_repl(mods, "versionNumber", prt->versionNumber); + ads_mod_repl(ctx, &mods, "printerName", prt->printerName); + ads_mod_repl(ctx, &mods, "serverName", prt->serverName); + ads_mod_repl(ctx, &mods, "shortServerName", prt->shortServerName); + ads_mod_repl(ctx, &mods, "uNCName", prt->uNCName); + ads_mod_repl(ctx, &mods, "versionNumber", prt->versionNumber); /* now the optional ones */ - ads_mod_repl_list(mods, "description", prt->description); - ads_mod_repl(mods, "assetNumber",prt->assetNumber); - ads_mod_repl(mods, "bytesPerMinute",prt->bytesPerMinute); - ads_mod_repl(mods, "defaultPriority",prt->defaultPriority); - ads_mod_repl(mods, "driverName", prt->driverName); - ads_mod_repl(mods, "driverVersion",prt->driverVersion); - ads_mod_repl(mods, "location", prt->location); - ads_mod_repl(mods, "operatingSystem",prt->operatingSystem); - ads_mod_repl(mods, "operatingSystemHotfix",prt->operatingSystemHotfix); - ads_mod_repl(mods, "operatingSystemServicePack", + ads_mod_repl_list(ctx, &mods, "description", prt->description); + ads_mod_repl(ctx, &mods, "assetNumber",prt->assetNumber); + ads_mod_repl(ctx, &mods, "bytesPerMinute",prt->bytesPerMinute); + ads_mod_repl(ctx, &mods, "defaultPriority",prt->defaultPriority); + ads_mod_repl(ctx, &mods, "driverName", prt->driverName); + ads_mod_repl(ctx, &mods, "driverVersion",prt->driverVersion); + ads_mod_repl(ctx, &mods, "location", prt->location); + ads_mod_repl(ctx, &mods, "operatingSystem",prt->operatingSystem); + ads_mod_repl(ctx, &mods, "operatingSystemHotfix", + prt->operatingSystemHotfix); + ads_mod_repl(ctx, &mods, "operatingSystemServicePack", prt->operatingSystemServicePack); - ads_mod_repl(mods, "operatingSystemVersion", + ads_mod_repl(ctx, &mods, "operatingSystemVersion", prt->operatingSystemVersion); - ads_mod_repl(mods, "physicalLocationObject", + ads_mod_repl(ctx, &mods, "physicalLocationObject", prt->physicalLocationObject); - ads_mod_repl_list(mods, "portName", prt->portName); - ads_mod_repl(mods, "printStartTime", prt->printStartTime); - ads_mod_repl(mods, "printEndTime", prt->printEndTime); - ads_mod_repl_list(mods, "printBinNames", prt->printBinNames); + ads_mod_repl_list(ctx, &mods, "portName", prt->portName); + ads_mod_repl(ctx, &mods, "printStartTime", prt->printStartTime); + ads_mod_repl(ctx, &mods, "printEndTime", prt->printEndTime); + ads_mod_repl_list(ctx, &mods, "printBinNames", prt->printBinNames); /*... and many others */ /* do the ldap modify */ - status = ads_gen_mod(ads, prt_dn, *mods); + status = ads_gen_mod(ads, prt_dn, mods); /* free mod list, mods, and values */ - ads_free_mods(*mods); + talloc_destroy(ctx); return status; } @@ -109,16 +114,27 @@ static ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, const ADS_PRINTER_ENTRY *prt) { ADS_STATUS status; - + TALLOC_CTX *ctx; + ADS_MODLIST mods; + + if (!(ctx = talloc_init_named("add_printer_entry"))) + return ADS_ERROR(LDAP_NO_MEMORY); + + if (!(mods = ads_init_mods(ctx))) + return ADS_ERROR(LDAP_NO_MEMORY); + /* These are the fields a printQueue must contain */ - status = ads_gen_add(ads, prt_dn, - "uNCName", prt->uNCName, NULL, - "versionNumber", prt->versionNumber, NULL, - "serverName", prt->serverName, NULL, - "shortServerName", prt->shortServerName, NULL, - "printerName", prt->printerName, NULL, - "objectClass", "printQueue", NULL, - NULL); + ads_mod_add(ctx, &mods, "uNCName", prt->uNCName); + ads_mod_add(ctx, &mods, "versionNumber", prt->versionNumber); + ads_mod_add(ctx, &mods, "serverName", prt->serverName); + ads_mod_add(ctx, &mods, "shortServerName", prt->shortServerName); + ads_mod_add(ctx, &mods, "printerName", prt->printerName); + ads_mod_add(ctx, &mods, "objectClass", "printQueue"); + + + status = ads_gen_add(ads, prt_dn, mods); + + talloc_destroy(ctx); return status; }