s3 net: Fix compile warnings
[nivanova/samba-autobuild/.git] / source3 / utils / net_idmap.c
index b0024895f73e06ab19cb7ebfb02ed8403d2b83c6..32680e0deeda7ce68ca8315c86b31d6249ba663e 100644 (file)
@@ -1,27 +1,29 @@
-/* 
-   Samba Unix/Linux SMB client library 
-   Distributed SMB/CIFS Server Management Utility 
+/*
+   Samba Unix/Linux SMB client library
+   Distributed SMB/CIFS Server Management Utility
    Copyright (C) 2003 Andrew Bartlett (abartlet@samba.org)
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
+#define FOO(x) (x)
 #include "includes.h"
 #include "utils/net.h"
 
 #define ALLOC_CHECK(mem) do { \
        if (!mem) { \
-               d_fprintf(stderr, "Out of memory!\n"); \
+               d_fprintf(stderr, _("Out of memory!\n")); \
                talloc_free(ctx); \
                return -1; \
        } } while(0)
@@ -35,12 +37,12 @@ static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb,
                                    void *unused)
 {
        if (strcmp((char *)key.dptr, "USER HWM") == 0) {
-               printf("USER HWM %d\n", IVAL(data.dptr,0));
+               printf(_("USER HWM %d\n"), IVAL(data.dptr,0));
                return 0;
        }
 
        if (strcmp((char *)key.dptr, "GROUP HWM") == 0) {
-               printf("GROUP HWM %d\n", IVAL(data.dptr,0));
+               printf(_("GROUP HWM %d\n"), IVAL(data.dptr,0));
                return 0;
        }
 
@@ -54,17 +56,23 @@ static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb,
 /***********************************************************
  Dump the current idmap
  **********************************************************/
-static int net_idmap_dump(int argc, const char **argv)
+static int net_idmap_dump(struct net_context *c, int argc, const char **argv)
 {
        TDB_CONTEXT *idmap_tdb;
 
-       if ( argc != 1 )
-               return net_help_idmap( argc, argv );
+       if ( argc != 1  || c->display_usage) {
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net idmap dump <inputfile>\n"
+                          "  Dump current ID mapping.\n"
+                          "    inputfile\tTDB file to read mappings from.\n"));
+               return c->display_usage?0:-1;
+       }
 
        idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0);
 
        if (idmap_tdb == NULL) {
-               d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]);
+               d_fprintf(stderr, _("Could not open idmap: %s\n"), argv[0]);
                return -1;
        }
 
@@ -79,13 +87,24 @@ static int net_idmap_dump(int argc, const char **argv)
  Write entries from stdin to current local idmap
  **********************************************************/
 
-static int net_idmap_restore(int argc, const char **argv)
+static int net_idmap_restore(struct net_context *c, int argc, const char **argv)
 {
        TALLOC_CTX *ctx;
        FILE *input;
 
+       if (c->display_usage) {
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net idmap restore [inputfile]\n"
+                          "  Restore ID mappings from file\n"
+                          "    inputfile\tFile to load ID mappings from. If "
+                          "not given, load data from stdin.\n"));
+               return 0;
+       }
+
        if (! winbind_ping()) {
-               d_fprintf(stderr, "To use net idmap Winbindd must be running.\n");
+               d_fprintf(stderr,
+                         _("To use net idmap Winbindd must be running.\n"));
                return -1;
        }
 
@@ -122,7 +141,8 @@ static int net_idmap_restore(int argc, const char **argv)
                        /* set uid hwm */
                        wbc_status = wbcSetUidHwm(idval);
                        if (!WBC_ERROR_IS_OK(wbc_status)) {
-                               d_fprintf(stderr, "Could not set USER HWM: %s\n",
+                               d_fprintf(stderr,
+                                         _("Could not set USER HWM: %s\n"),
                                          wbcErrorString(wbc_status));
                        }
                        continue;
@@ -130,18 +150,20 @@ static int net_idmap_restore(int argc, const char **argv)
                        /* set gid hwm */
                        wbc_status = wbcSetGidHwm(idval);
                        if (!WBC_ERROR_IS_OK(wbc_status)) {
-                               d_fprintf(stderr, "Could not set GROUP HWM: %s\n",
+                               d_fprintf(stderr,
+                                         _("Could not set GROUP HWM: %s\n"),
                                          wbcErrorString(wbc_status));
                        }
                        continue;
                } else {
-                       d_fprintf(stderr, "ignoring invalid line [%s]\n", line);
+                       d_fprintf(stderr, _("ignoring invalid line [%s]\n"),
+                                 line);
                        continue;
                }
 
                wbc_status = wbcStringToSid(sid_string, &sid);
                if (!WBC_ERROR_IS_OK(wbc_status)) {
-                       d_fprintf(stderr, "ignoring invalid sid [%s]: %s\n",
+                       d_fprintf(stderr, _("ignoring invalid sid [%s]: %s\n"),
                                  sid_string, wbcErrorString(wbc_status));
                        continue;
                }
@@ -152,7 +174,8 @@ static int net_idmap_restore(int argc, const char **argv)
                        wbc_status = wbcSetGidMapping(idval, &sid);
                }
                if (!WBC_ERROR_IS_OK(wbc_status)) {
-                       d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s: %s\n",
+                       d_fprintf(stderr,
+                                 _("Could not set mapping of %s %lu to sid %s: %s\n"),
                                 (type == ID_TYPE_GID) ? "GID" : "UID",
                                 idval, sid_string,
                                 wbcErrorString(wbc_status));
@@ -171,15 +194,15 @@ static int net_idmap_restore(int argc, const char **argv)
 /***********************************************************
  Delete a SID mapping from a winbindd_idmap.tdb
  **********************************************************/
-static int net_idmap_delete(int argc, const char **argv)
+static int net_idmap_delete(struct net_context *c, int argc, const char **argv)
 {
-       d_printf("Not Implemented yet\n");
+       d_printf("%s\n", _("Not implemented yet"));
        return -1;
 }
 
-static int net_idmap_set(int argc, const char **argv)
+static int net_idmap_set(struct net_context *c, int argc, const char **argv)
 {
-       d_printf("Not Implemented yet\n");
+       d_printf("%s\n", _("Not implemented yet"));
        return -1;
 }
 bool idmap_store_secret(const char *backend, bool alloc,
@@ -206,7 +229,7 @@ bool idmap_store_secret(const char *backend, bool alloc,
 }
 
 
-static int net_idmap_secret(int argc, const char **argv)
+static int net_idmap_secret(struct net_context *c, int argc, const char **argv)
 {
        TALLOC_CTX *ctx;
        const char *secret;
@@ -216,8 +239,16 @@ static int net_idmap_secret(int argc, const char **argv)
        char *opt = NULL;
        bool ret;
 
-       if (argc != 2) {
-               return net_help_idmap(argc, argv);
+       if (argc != 2 || c->display_usage) {
+               d_printf("%s\n%s",
+                        _("Usage:"),
+                        _("net idmap secret {<DOMAIN>|alloc} <secret>\n"
+                          "  Set the secret for the specified domain "
+                          "(or alloc module)\n"
+                          "    DOMAIN\tDomain to set secret for.\n"
+                          "    alloc\tSet secret for the alloc module\n"
+                          "    secret\tNew secret to set.\n"));
+               return c->display_usage?0:-1;
        }
 
        secret = argv[1];
@@ -240,7 +271,8 @@ static int net_idmap_secret(int argc, const char **argv)
        }
 
        if ( ( ! backend) || ( ! strequal(backend, "ldap"))) {
-               d_fprintf(stderr, "The only currently supported backend is LDAP\n");
+               d_fprintf(stderr,
+                         _("The only currently supported backend is LDAP\n"));
                talloc_free(ctx);
                return -1;
        }
@@ -249,7 +281,9 @@ static int net_idmap_secret(int argc, const char **argv)
 
                dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
                if ( ! dn) {
-                       d_fprintf(stderr, "Missing ldap_user_dn option for domain %s\n", domain);
+                       d_fprintf(stderr,
+                                 _("Missing ldap_user_dn option for domain "
+                                   "%s\n"), domain);
                        talloc_free(ctx);
                        return -1;
                }
@@ -258,7 +292,9 @@ static int net_idmap_secret(int argc, const char **argv)
        } else {
                dn = lp_parm_const_string(-1, "idmap alloc config", "ldap_user_dn", NULL);
                if ( ! dn) {
-                       d_fprintf(stderr, "Missing ldap_user_dn option for alloc backend\n");
+                       d_fprintf(stderr,
+                                 _("Missing ldap_user_dn option for alloc "
+                                   "backend\n"));
                        talloc_free(ctx);
                        return -1;
                }
@@ -267,32 +303,33 @@ static int net_idmap_secret(int argc, const char **argv)
        }
 
        if ( ! ret) {
-               d_fprintf(stderr, "Failed to store secret\n");
+               d_fprintf(stderr, _("Failed to store secret\n"));
                talloc_free(ctx);
                return -1;
        }
 
-       d_printf("Secret stored\n");
+       d_printf(_("Secret stored\n"));
        return 0;
 }
 
-int net_help_idmap(int argc, const char **argv)
+int net_help_idmap(struct net_context *c, int argc, const char **argv)
 {
-       d_printf("net idmap dump <inputfile>\n"\
-                "    Dump current id mapping\n");
+       d_printf(_("net idmap dump <inputfile>\n"
+                  "    Dump current id mapping\n"));
 
-       d_printf("net idmap restore\n"\
-                "    Restore entries from stdin\n");
+       d_printf(_("net idmap restore\n"
+                  "    Restore entries from stdin\n"));
 
        /* Deliberately *not* document net idmap delete */
 
-       d_printf("net idmap secret <DOMAIN>|alloc <secret>\n"\
-                "    Set the secret for the specified DOMAIN (or the alloc module)\n");
+       d_printf(_("net idmap secret <DOMAIN>|alloc <secret>\n"
+                  "    Set the secret for the specified DOMAIN (or the alloc "
+                  "module)\n"));
 
        return -1;
 }
 
-static int net_idmap_aclmapset(int argc, const char **argv)
+static int net_idmap_aclmapset(struct net_context *c, int argc, const char **argv)
 {
        TALLOC_CTX *mem_ctx;
        int result = -1;
@@ -302,42 +339,42 @@ static int net_idmap_aclmapset(int argc, const char **argv)
        struct db_record *rec;
        NTSTATUS status;
 
-       if (argc != 3) {
-               d_fprintf(stderr, "usage: net idmap aclmapset <tdb> "
-                         "<src-sid> <dst-sid>\n");
+       if (argc != 3 || c->display_usage) {
+               d_fprintf(stderr, "%s net idmap aclmapset <tdb> "
+                         "<src-sid> <dst-sid>\n", _("Usage:"));
                return -1;
        }
 
        if (!(mem_ctx = talloc_init("net idmap aclmapset"))) {
-               d_fprintf(stderr, "talloc_init failed\n");
+               d_fprintf(stderr, _("talloc_init failed\n"));
                return -1;
        }
 
        if (!(db = db_open(mem_ctx, argv[0], 0, TDB_DEFAULT,
                           O_RDWR|O_CREAT, 0600))) {
-               d_fprintf(stderr, "db_open failed: %s\n", strerror(errno));
+               d_fprintf(stderr, _("db_open failed: %s\n"), strerror(errno));
                goto fail;
        }
 
        if (!string_to_sid(&src_sid, argv[1])) {
-               d_fprintf(stderr, "%s is not a valid sid\n", argv[1]);
+               d_fprintf(stderr, _("%s is not a valid sid\n"), argv[1]);
                goto fail;
        }
 
        if (!string_to_sid(&dst_sid, argv[2])) {
-               d_fprintf(stderr, "%s is not a valid sid\n", argv[2]);
+               d_fprintf(stderr, _("%s is not a valid sid\n"), argv[2]);
                goto fail;
        }
 
        if (!(src = sid_string_talloc(mem_ctx, &src_sid))
            || !(dst = sid_string_talloc(mem_ctx, &dst_sid))) {
-               d_fprintf(stderr, "talloc_strdup failed\n");
+               d_fprintf(stderr, _("talloc_strdup failed\n"));
                goto fail;
        }
 
        if (!(rec = db->fetch_locked(
                      db, mem_ctx, string_term_tdb_data(src)))) {
-               d_fprintf(stderr, "could not fetch db record\n");
+               d_fprintf(stderr, _("could not fetch db record\n"));
                goto fail;
        }
 
@@ -345,7 +382,7 @@ static int net_idmap_aclmapset(int argc, const char **argv)
        TALLOC_FREE(rec);
 
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "could not store record: %s\n",
+               d_fprintf(stderr, _("could not store record: %s\n"),
                          nt_errstr(status));
                goto fail;
        }
@@ -359,20 +396,61 @@ fail:
 /***********************************************************
  Look at the current idmap
  **********************************************************/
-int net_idmap(int argc, const char **argv)
+int net_idmap(struct net_context *c, int argc, const char **argv)
 {
        struct functable func[] = {
-               {"dump", net_idmap_dump},
-               {"restore", net_idmap_restore},
-               {"setmap", net_idmap_set },
-               {"delete", net_idmap_delete},
-               {"secret", net_idmap_secret},
-               {"aclmapset", net_idmap_aclmapset},
-               {"help", net_help_idmap},
-               {NULL, NULL}
+               {
+                       "dump",
+                       net_idmap_dump,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Dump the current ID mappings"),
+                       N_("net idmap dump\n"
+                          "  Dump the current ID mappings")
+               },
+               {
+                       "restore",
+                       net_idmap_restore,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Restore entries from stdin"),
+                       N_("net idmap restore\n"
+                          "  Restore entries from stdin")
+               },
+               {
+                       "setmap",
+                       net_idmap_set,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Not implemented yet"),
+                       N_("net idmap setmap\n"
+                          "  Not implemented yet")
+               },
+               {
+                       "delete",
+                       net_idmap_delete,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Not implemented yet"),
+                       N_("net idmap delete\n"
+                          "  Not implemented yet")
+               },
+               {
+                       "secret",
+                       net_idmap_secret,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Set secret for specified domain"),
+                       N_("net idmap secret {<DOMAIN>|alloc} <secret>\n"
+                          "  Set secret for specified domain or alloc module")
+               },
+               {
+                       "aclmapset",
+                       net_idmap_aclmapset,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Set acl map"),
+                       N_("net idmap aclmapset\n"
+                          "  Set acl map")
+               },
+               {NULL, NULL, 0, NULL, NULL}
        };
 
-       return net_run_function(argc, argv, func, net_help_idmap);
+       return net_run_function(c, argc, argv, "net idmap", func);
 }