At http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/
------------------------------------------------------------ revno: 5292 revision-id: [EMAIL PROTECTED] parent: [EMAIL PROTECTED] committer: Michael Adam <[EMAIL PROTECTED]> branch nick: SAMBA_3_0-registry.bzr timestamp: Tue 2007-03-20 16:20:51 +0100 message: First _unfinished_ version of "net conf import". This function is to import registry shares from a file in smb.conf format. Currently it loads a file given on the command line via lp_load and dumps the read config out to stdout. Once the loop is finished, the data will be put into the registry instead of dumped. modified: source/utils/net_conf.c net_conf.c-20070228210606-uywdn1acd043wgvt-1 === modified file 'source/utils/net_conf.c' --- a/source/utils/net_conf.c 2007-03-13 16:52:01 +0000 +++ b/source/utils/net_conf.c 2007-03-20 15:20:51 +0000 @@ -44,6 +44,24 @@ * usage functions */ +static int net_conf_list_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf list\n"); + return -1; +} + +static int net_conf_import_usage(int argc, const char**argv) +{ + d_printf("USAGE: net conf import <filename>\n"); + return -1; +} + +static int net_conf_listshares_usage(int argc, const char **argv) +{ + d_printf("USAGE: net conf listshares\n"); + return -1; +} + static int net_conf_showshare_usage(int argc, const char **argv) { d_printf("USAGE: net conf showshare <sharename>\n"); @@ -89,18 +107,6 @@ return -1; } -static int net_conf_list_usage(int argc, const char **argv) -{ - d_printf("USAGE: net conf list\n"); - return -1; -} - -static int net_conf_listshares_usage(int argc, const char **argv) -{ - d_printf("USAGE: net conf listshares\n"); - return -1; -} - /* * Helper functions @@ -272,6 +278,89 @@ return ret; } +int net_conf_import(int argc, const char **argv) +{ + int ret = -1; + const char *filename = NULL; + TALLOC_CTX *ctx; + struct share_iterator *shares; + struct share_params *share; + struct parm_struct *parm; + int i = 0; + char *utf8_s1; + + ctx = talloc_init("net_conf_import"); + + if (argc != 1) { + net_conf_import_usage(argc, argv); + goto done; + } + + filename = argv[0]; + DEBUG(3,("net_conf_import: reading configuration from file %s.\n", + filename)); + + /* TODO: check for existence and readability */ + + if (!lp_load(filename, + False, /* global_only */ + False, /* save_defaults */ + False, /* add_ipc */ + False)) /* initialize_globals */ + { + d_fprintf(stderr, "Error parsing configuration file.\n"); + goto done; + } + + if (!(shares = share_list_all(ctx))) { + d_fprintf(stderr, "Could not list shares...\n"); + goto done; + } + while ((share = next_share(shares)) != NULL) { + d_printf("TEST: snum %i : [%s]\n", share->service, + lp_servicename(share->service)); + i = 0; + while ((parm = lp_next_parameter(share->service, &i, 0))) + { + if (parm->type != P_SEP) { + d_printf("TEST: param %3d : %s = ", i, + parm->label); + } + switch (parm->type) { + case P_CHAR: + d_printf("%c", *(char *)(parm->ptr)); + break; + case P_STRING: + case P_USTRING: + d_printf("%s\n", *(char **)(parm->ptr)); + break; + case P_GSTRING: + case P_UGSTRING: + d_printf("%s\n", (char *)(parm->ptr)); + break; + case P_BOOL: + d_printf("%s\n", BOOLSTR(*(BOOL *)(parm->ptr))); + break; + case P_BOOLREV: + d_printf("%s\n", BOOLSTR(!*(BOOL *)(parm->ptr))); + break; + case P_SEP: + break; + default: + d_printf("<type unimplemented>\n"); + break; + } + } + d_printf("TEST: -----------\n"); + } + + ret = 0; + +done: + TALLOC_FREE(ctx); + return ret; +} + int net_conf_listshares(int argc, const char **argv) { WERROR werr = WERR_OK; @@ -722,6 +811,8 @@ struct functable2 func[] = { {"list", net_conf_list, "Dump the complete configuration in smb.conf like format."}, + {"import", net_conf_import, + "Import configuration from file in smb.conf format."}, {"listshares", net_conf_listshares, "List the registry shares."}, {"showshare", net_conf_showshare,