Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/utils/net_idmap.c

    r414 r745  
    1818*/
    1919
    20 #define FOO(x) (x)
    2120#include "includes.h"
     21#include "system/filesys.h"
    2222#include "utils/net.h"
     23#include "secrets.h"
     24#include "idmap.h"
     25#include "dbwrap.h"
     26#include "../libcli/security/security.h"
     27#include "net_idmap_check.h"
     28#include "util_tdb.h"
    2329
    2430#define ALLOC_CHECK(mem) do { \
     
    3238 Helper function for net_idmap_dump. Dump one entry.
    3339 **********************************************************/
    34 static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb,
    35                                     TDB_DATA key,
    36                                     TDB_DATA data,
     40static int net_idmap_dump_one_entry(struct db_record *rec,
    3741                                    void *unused)
    3842{
    39         if (strcmp((char *)key.dptr, "USER HWM") == 0) {
    40                 printf(_("USER HWM %d\n"), IVAL(data.dptr,0));
     43        if (strcmp((char *)rec->key.dptr, "USER HWM") == 0) {
     44                printf(_("USER HWM %d\n"), IVAL(rec->value.dptr,0));
    4145                return 0;
    4246        }
    4347
    44         if (strcmp((char *)key.dptr, "GROUP HWM") == 0) {
    45                 printf(_("GROUP HWM %d\n"), IVAL(data.dptr,0));
     48        if (strcmp((char *)rec->key.dptr, "GROUP HWM") == 0) {
     49                printf(_("GROUP HWM %d\n"), IVAL(rec->value.dptr,0));
    4650                return 0;
    4751        }
    4852
    49         if (strncmp((char *)key.dptr, "S-", 2) != 0)
     53        if (strncmp((char *)rec->key.dptr, "S-", 2) != 0)
    5054                return 0;
    5155
    52         printf("%s %s\n", data.dptr, key.dptr);
     56        printf("%s %s\n", rec->value.dptr, rec->key.dptr);
    5357        return 0;
     58}
     59
     60static const char* net_idmap_dbfile(struct net_context *c)
     61{
     62        const char* dbfile = NULL;
     63
     64        if (c->opt_db != NULL) {
     65                dbfile = talloc_strdup(talloc_tos(), c->opt_db);
     66                if (dbfile == NULL) {
     67                        d_fprintf(stderr, _("Out of memory!\n"));
     68                }
     69        } else if (strequal(lp_idmap_backend(), "tdb")) {
     70                dbfile = state_path("winbindd_idmap.tdb");
     71                if (dbfile == NULL) {
     72                        d_fprintf(stderr, _("Out of memory!\n"));
     73                }
     74        } else if (strequal(lp_idmap_backend(), "tdb2")) {
     75                dbfile = lp_parm_talloc_string(-1, "tdb", "idmap2.tdb", NULL);
     76                if (dbfile == NULL) {
     77                        dbfile = talloc_asprintf(talloc_tos(), "%s/idmap2.tdb",
     78                                                 lp_private_dir());
     79                }
     80                if (dbfile == NULL) {
     81                        d_fprintf(stderr, _("Out of memory!\n"));
     82                }
     83        } else {
     84                char* backend = talloc_strdup(talloc_tos(), lp_idmap_backend());
     85                char* args = strchr(backend, ':');
     86                if (args != NULL) {
     87                        *args = '\0';
     88                }
     89
     90                d_printf(_("Sorry, 'idmap backend = %s' is currently not supported\n"),
     91                         backend);
     92
     93                talloc_free(backend);
     94        }
     95
     96        return dbfile;
    5497}
    5598
     
    59102static int net_idmap_dump(struct net_context *c, int argc, const char **argv)
    60103{
    61         TDB_CONTEXT *idmap_tdb;
    62 
    63         if ( argc != 1  || c->display_usage) {
     104        struct db_context *db;
     105        TALLOC_CTX *mem_ctx;
     106        const char* dbfile;
     107        int ret = -1;
     108
     109        if ( argc > 1  || c->display_usage) {
    64110                d_printf("%s\n%s",
    65111                         _("Usage:"),
    66                          _("net idmap dump <inputfile>\n"
     112                         _("net idmap dump [[--db=]<inputfile>]\n"
    67113                           "  Dump current ID mapping.\n"
    68114                           "    inputfile\tTDB file to read mappings from.\n"));
     
    70116        }
    71117
    72         idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0);
    73 
    74         if (idmap_tdb == NULL) {
    75                 d_fprintf(stderr, _("Could not open idmap: %s\n"), argv[0]);
    76                 return -1;
    77         }
    78 
    79         tdb_traverse(idmap_tdb, net_idmap_dump_one_entry, NULL);
    80 
    81         tdb_close(idmap_tdb);
    82 
    83         return 0;
     118        mem_ctx = talloc_stackframe();
     119
     120        dbfile = (argc > 0) ? argv[0] : net_idmap_dbfile(c);
     121        if (dbfile == NULL) {
     122                goto done;
     123        }
     124        d_fprintf(stderr, _("dumping id mapping from %s\n"), dbfile);
     125
     126        db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0);
     127        if (db == NULL) {
     128                d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
     129                          dbfile, strerror(errno));
     130                goto done;
     131        }
     132
     133        db->traverse_read(db, net_idmap_dump_one_entry, NULL);
     134        ret = 0;
     135
     136done:
     137        talloc_free(mem_ctx);
     138        return ret;
    84139}
    85140
     
    88143 **********************************************************/
    89144
     145static int net_idmap_store_id_mapping(struct db_context *db,
     146                                      enum id_type type,
     147                                      unsigned long idval,
     148                                      const char *sid_string)
     149{
     150        NTSTATUS status;
     151        char *idstr = NULL;
     152
     153        switch(type) {
     154        case ID_TYPE_UID:
     155                idstr = talloc_asprintf(talloc_tos(), "UID %lu", idval);
     156                break;
     157        case ID_TYPE_GID:
     158                idstr = talloc_asprintf(talloc_tos(), "GID %lu", idval);
     159                break;
     160        default:
     161                d_fprintf(stderr, "Invalid id mapping type: %d\n", type);
     162                return -1;
     163        }
     164
     165        status = dbwrap_store_bystring(db, idstr,
     166                                       string_term_tdb_data(sid_string),
     167                                       TDB_REPLACE);
     168        if (!NT_STATUS_IS_OK(status)) {
     169                d_fprintf(stderr, "Error storing ID -> SID: "
     170                         "%s\n", nt_errstr(status));
     171                talloc_free(idstr);
     172                return -1;
     173        }
     174        status = dbwrap_store_bystring(db, sid_string,
     175                                       string_term_tdb_data(idstr),
     176                                       TDB_REPLACE);
     177        if (!NT_STATUS_IS_OK(status)) {
     178                d_fprintf(stderr, "Error storing SID -> ID: "
     179                         "%s\n", nt_errstr(status));
     180                talloc_free(idstr);
     181                return -1;
     182        }
     183
     184        return 0;
     185}
     186
    90187static int net_idmap_restore(struct net_context *c, int argc, const char **argv)
    91188{
    92         TALLOC_CTX *ctx;
    93         FILE *input;
     189        TALLOC_CTX *mem_ctx;
     190        FILE *input = NULL;
     191        struct db_context *db;
     192        const char *dbfile = NULL;
     193        int ret = 0;
    94194
    95195        if (c->display_usage) {
    96196                d_printf("%s\n%s",
    97197                         _("Usage:"),
    98                          _("net idmap restore [inputfile]\n"
     198                         _("net idmap restore [--db=<TDB>] [<inputfile>]\n"
    99199                           "  Restore ID mappings from file\n"
    100                            "    inputfile\tFile to load ID mappings from. If "
    101                            "not given, load data from stdin.\n"));
     200                           "    TDB\tFile to store ID mappings to."
     201                           "    inputfile\tFile to load ID mappings from. If not "
     202                           "given, load data from stdin.\n"));
    102203                return 0;
    103204        }
    104205
    105         if (! winbind_ping()) {
    106                 d_fprintf(stderr,
    107                           _("To use net idmap Winbindd must be running.\n"));
    108                 return -1;
    109         }
    110 
    111         ctx = talloc_new(NULL);
    112         ALLOC_CHECK(ctx);
     206        mem_ctx = talloc_stackframe();
     207
     208        dbfile = net_idmap_dbfile(c);
     209
     210        if (dbfile == NULL) {
     211                ret = -1;
     212                goto done;
     213        }
     214
     215        d_fprintf(stderr, _("restoring id mapping to %s\n"), dbfile);
    113216
    114217        if (argc == 1) {
    115218                input = fopen(argv[0], "r");
     219                if (input == NULL) {
     220                        d_fprintf(stderr, _("Could not open input file (%s): %s\n"),
     221                                  argv[0], strerror(errno));
     222                        ret = -1;
     223                        goto done;
     224                }
    116225        } else {
    117226                input = stdin;
     227        }
     228
     229        db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
     230        if (db == NULL) {
     231                d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
     232                          dbfile, strerror(errno));
     233                ret = -1;
     234                goto done;
     235        }
     236
     237        if (db->transaction_start(db) != 0) {
     238                d_fprintf(stderr, _("Failed to start transaction.\n"));
     239                ret = -1;
     240                goto done;
    118241        }
    119242
     
    121244                char line[128], sid_string[128];
    122245                int len;
    123                 struct wbcDomainSid sid;
    124                 enum id_type type = ID_TYPE_NOT_SPECIFIED;
    125246                unsigned long idval;
    126                 wbcErr wbc_status;
    127247
    128248                if (fgets(line, 127, input) == NULL)
     
    134254                        line[len-1] = '\0';
    135255
    136                 if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2) {
    137                         type = ID_TYPE_GID;
    138                 } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2) {
    139                         type = ID_TYPE_UID;
     256                if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2)
     257                {
     258                        ret = net_idmap_store_id_mapping(db, ID_TYPE_GID,
     259                                                         idval, sid_string);
     260                        if (ret != 0) {
     261                                break;
     262                        }
     263                } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2)
     264                {
     265                        ret = net_idmap_store_id_mapping(db, ID_TYPE_UID,
     266                                                         idval, sid_string);
     267                        if (ret != 0) {
     268                                break;
     269                        }
    140270                } else if (sscanf(line, "USER HWM %lu", &idval) == 1) {
    141                         /* set uid hwm */
    142                         wbc_status = wbcSetUidHwm(idval);
    143                         if (!WBC_ERROR_IS_OK(wbc_status)) {
     271                        ret = dbwrap_store_int32(db, "USER HWM", idval);
     272                        if (ret != 0) {
     273                                d_fprintf(stderr, _("Could not store USER HWM.\n"));
     274                                break;
     275                        }
     276                } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) {
     277                        ret = dbwrap_store_int32(db, "GROUP HWM", idval);
     278                        if (ret != 0) {
    144279                                d_fprintf(stderr,
    145                                           _("Could not set USER HWM: %s\n"),
    146                                           wbcErrorString(wbc_status));
     280                                          _("Could not store GROUP HWM.\n"));
     281                                break;
    147282                        }
    148                         continue;
    149                 } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) {
    150                         /* set gid hwm */
    151                         wbc_status = wbcSetGidHwm(idval);
    152                         if (!WBC_ERROR_IS_OK(wbc_status)) {
    153                                 d_fprintf(stderr,
    154                                           _("Could not set GROUP HWM: %s\n"),
    155                                           wbcErrorString(wbc_status));
    156                         }
    157                         continue;
    158283                } else {
    159284                        d_fprintf(stderr, _("ignoring invalid line [%s]\n"),
     
    161286                        continue;
    162287                }
    163 
    164                 wbc_status = wbcStringToSid(sid_string, &sid);
    165                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    166                         d_fprintf(stderr, _("ignoring invalid sid [%s]: %s\n"),
    167                                   sid_string, wbcErrorString(wbc_status));
    168                         continue;
    169                 }
    170 
    171                 if (type == ID_TYPE_UID) {
    172                         wbc_status = wbcSetUidMapping(idval, &sid);
    173                 } else {
    174                         wbc_status = wbcSetGidMapping(idval, &sid);
    175                 }
    176                 if (!WBC_ERROR_IS_OK(wbc_status)) {
    177                         d_fprintf(stderr,
    178                                   _("Could not set mapping of %s %lu to sid %s: %s\n"),
    179                                  (type == ID_TYPE_GID) ? "GID" : "UID",
    180                                  idval, sid_string,
    181                                  wbcErrorString(wbc_status));
    182                         continue;
    183                 }
    184         }
    185 
    186         if (input != stdin) {
     288        }
     289
     290        if (ret == 0) {
     291                if(db->transaction_commit(db) != 0) {
     292                        d_fprintf(stderr, _("Failed to commit transaction.\n"));
     293                        ret = -1;
     294                }
     295        } else {
     296                if (db->transaction_cancel(db) != 0) {
     297                        d_fprintf(stderr, _("Failed to cancel transaction.\n"));
     298                }
     299        }
     300
     301done:
     302        if ((input != NULL) && (input != stdin)) {
    187303                fclose(input);
    188304        }
    189305
    190         talloc_free(ctx);
    191         return 0;
     306        talloc_free(mem_ctx);
     307        return ret;
     308}
     309
     310static
     311NTSTATUS dbwrap_delete_mapping(struct db_context *db, TDB_DATA key1, bool force)
     312{
     313        TALLOC_CTX* mem_ctx = talloc_tos();
     314        struct db_record *rec1=NULL, *rec2=NULL;
     315        TDB_DATA key2;
     316        bool is_valid_mapping;
     317        NTSTATUS status = NT_STATUS_OK;
     318
     319        rec1 = db->fetch_locked(db, mem_ctx, key1);
     320        if (rec1 == NULL) {
     321                DEBUG(1, ("failed to fetch: %.*s\n", (int)key1.dsize, key1.dptr));
     322                status = NT_STATUS_NO_MEMORY;
     323                goto done;
     324        }
     325        key2 = rec1->value;
     326        if (key2.dptr == NULL) {
     327                DEBUG(1, ("could not find %.*s\n", (int)key1.dsize, key1.dptr));
     328                status = NT_STATUS_NOT_FOUND;
     329                goto done;
     330        }
     331
     332        DEBUG(2, ("mapping: %.*s -> %.*s\n",
     333                  (int)key1.dsize, key1.dptr, (int)key2.dsize, key2.dptr));
     334
     335        rec2 = db->fetch_locked(db, mem_ctx, key2);
     336        if (rec2 == NULL) {
     337                DEBUG(1, ("failed to fetch: %.*s\n", (int)key2.dsize, key2.dptr));
     338                status = NT_STATUS_NO_MEMORY;
     339                goto done;
     340        }
     341
     342        is_valid_mapping = tdb_data_equal(key1, rec2->value);
     343
     344        if (!is_valid_mapping) {
     345                DEBUG(1, ("invalid mapping: %.*s -> %.*s -> %.*s\n",
     346                          (int)key1.dsize, key1.dptr, (int)key2.dsize, key2.dptr,
     347                          (int)rec2->value.dsize, rec2->value.dptr ));
     348                if ( !force ) {
     349                        status = NT_STATUS_FILE_INVALID;
     350                        goto done;
     351                }
     352        }
     353
     354        status = rec1->delete_rec(rec1);
     355        if (!NT_STATUS_IS_OK(status)) {
     356                DEBUG(1, ("failed to delete: %.*s\n", (int)key1.dsize, key1.dptr));
     357                goto done;
     358        }
     359
     360        if (is_valid_mapping) {
     361                status = rec2->delete_rec(rec2);
     362                if (!NT_STATUS_IS_OK(status)) {
     363                        DEBUG(1, ("failed to delete: %.*s\n", (int)key2.dsize, key2.dptr));
     364                }
     365        }
     366done:
     367        TALLOC_FREE(rec1);
     368        TALLOC_FREE(rec2);
     369        return status;
     370}
     371
     372static
     373NTSTATUS delete_mapping_action(struct db_context *db, void* data)
     374{
     375        return dbwrap_delete_mapping(db, *(TDB_DATA*)data, false);
     376}
     377static
     378NTSTATUS delete_mapping_action_force(struct db_context *db, void* data)
     379{
     380        return dbwrap_delete_mapping(db, *(TDB_DATA*)data, true);
    192381}
    193382
     
    195384 Delete a SID mapping from a winbindd_idmap.tdb
    196385 **********************************************************/
     386static bool delete_args_ok(int argc, const char **argv)
     387{
     388        if (argc != 1)
     389                return false;
     390        if (strncmp(argv[0], "S-", 2) == 0)
     391                return true;
     392        if (strncmp(argv[0], "GID ", 4) == 0)
     393                return true;
     394        if (strncmp(argv[0], "UID ", 4) == 0)
     395                return true;
     396        return false;
     397}
     398
    197399static int net_idmap_delete(struct net_context *c, int argc, const char **argv)
     400{
     401        int ret = -1;
     402        struct db_context *db;
     403        TALLOC_CTX *mem_ctx;
     404        TDB_DATA key;
     405        NTSTATUS status;
     406        const char* dbfile;
     407
     408        if ( !delete_args_ok(argc,argv) || c->display_usage) {
     409                d_printf("%s\n%s",
     410                         _("Usage:"),
     411                         _("net idmap delete [-f] [--db=<TDB>] <ID>\n"
     412                           "  Delete mapping of ID from TDB.\n"
     413                           "    -f\tforce\n"
     414                           "    TDB\tidmap database\n"
     415                           "    ID\tSID|GID|UID\n"));
     416                return c->display_usage ? 0 : -1;
     417        }
     418
     419        mem_ctx = talloc_stackframe();
     420
     421        dbfile = net_idmap_dbfile(c);
     422        if (dbfile == NULL) {
     423                goto done;
     424        }
     425        d_fprintf(stderr, _("deleting id mapping from %s\n"), dbfile);
     426
     427        db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR, 0);
     428        if (db == NULL) {
     429                d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
     430                          dbfile, strerror(errno));
     431                goto done;
     432        }
     433
     434        key = string_term_tdb_data(argv[0]);
     435
     436        status = dbwrap_trans_do(db, (c->opt_force
     437                                      ? delete_mapping_action_force
     438                                      : delete_mapping_action),  &key);
     439
     440        if (!NT_STATUS_IS_OK(status)) {
     441                d_fprintf(stderr, _("could not delete mapping: %s\n"),
     442                          nt_errstr(status));
     443                goto done;
     444        }
     445        ret = 0;
     446done:
     447        talloc_free(mem_ctx);
     448        return ret;
     449}
     450
     451static int net_idmap_set(struct net_context *c, int argc, const char **argv)
    198452{
    199453        d_printf("%s\n", _("Not implemented yet"));
    200454        return -1;
    201455}
    202 
    203 static int net_idmap_set(struct net_context *c, int argc, const char **argv)
    204 {
    205         d_printf("%s\n", _("Not implemented yet"));
    206         return -1;
    207 }
    208 bool idmap_store_secret(const char *backend, bool alloc,
    209                         const char *domain, const char *identity,
    210                         const char *secret)
     456static bool idmap_store_secret(const char *backend,
     457                               const char *domain,
     458                               const char *identity,
     459                               const char *secret)
    211460{
    212461        char *tmp;
     
    214463        bool ret;
    215464
    216         if (alloc) {
    217                 r = asprintf(&tmp, "IDMAP_ALLOC_%s", backend);
    218         } else {
    219                 r = asprintf(&tmp, "IDMAP_%s_%s", backend, domain);
    220         }
     465        r = asprintf(&tmp, "IDMAP_%s_%s", backend, domain);
    221466
    222467        if (r < 0) return false;
     
    242487        if (argc != 2 || c->display_usage) {
    243488                d_printf("%s\n%s",
    244                          _("Usage:"),
    245                          _("net idmap secret {<DOMAIN>|alloc} <secret>\n"
    246                            "  Set the secret for the specified domain "
    247                            "(or alloc module)\n"
     489                         _("Usage:\n"),
     490                         _("net idmap secret <DOMAIN> <secret>\n"
     491                           "  Set the secret for the specified domain\n"
    248492                           "    DOMAIN\tDomain to set secret for.\n"
    249                            "    alloc\tSet secret for the alloc module\n"
    250493                           "    secret\tNew secret to set.\n"));
    251494                return c->display_usage?0:-1;
     
    257500        ALLOC_CHECK(ctx);
    258501
    259         if (strcmp(argv[0], "alloc") == 0) {
    260                 domain = NULL;
    261                 backend = lp_idmap_alloc_backend();
    262         } else {
    263                 domain = talloc_strdup(ctx, argv[0]);
    264                 ALLOC_CHECK(domain);
    265 
    266                 opt = talloc_asprintf(ctx, "idmap config %s", domain);
    267                 ALLOC_CHECK(opt);
    268 
    269                 backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb"));
    270                 ALLOC_CHECK(backend);
    271         }
     502        domain = talloc_strdup(ctx, argv[0]);
     503        ALLOC_CHECK(domain);
     504
     505        opt = talloc_asprintf(ctx, "idmap config %s", domain);
     506        ALLOC_CHECK(opt);
     507
     508        backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb"));
     509        ALLOC_CHECK(backend);
    272510
    273511        if ( ( ! backend) || ( ! strequal(backend, "ldap"))) {
     
    278516        }
    279517
    280         if (domain) {
    281 
    282                 dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
    283                 if ( ! dn) {
    284                         d_fprintf(stderr,
    285                                   _("Missing ldap_user_dn option for domain "
    286                                     "%s\n"), domain);
    287                         talloc_free(ctx);
    288                         return -1;
    289                 }
    290 
    291                 ret = idmap_store_secret("ldap", false, domain, dn, secret);
    292         } else {
    293                 dn = lp_parm_const_string(-1, "idmap alloc config", "ldap_user_dn", NULL);
    294                 if ( ! dn) {
    295                         d_fprintf(stderr,
    296                                   _("Missing ldap_user_dn option for alloc "
    297                                     "backend\n"));
    298                         talloc_free(ctx);
    299                         return -1;
    300                 }
    301 
    302                 ret = idmap_store_secret("ldap", true, NULL, dn, secret);
    303         }
     518        dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
     519        if ( ! dn) {
     520                d_fprintf(stderr,
     521                          _("Missing ldap_user_dn option for domain %s\n"),
     522                          domain);
     523                talloc_free(ctx);
     524                return -1;
     525        }
     526
     527        ret = idmap_store_secret("ldap", domain, dn, secret);
    304528
    305529        if ( ! ret) {
     
    313537}
    314538
    315 int net_help_idmap(struct net_context *c, int argc, const char **argv)
    316 {
    317         d_printf(_("net idmap dump <inputfile>\n"
    318                    "    Dump current id mapping\n"));
    319 
    320         d_printf(_("net idmap restore\n"
    321                    "    Restore entries from stdin\n"));
    322 
    323         /* Deliberately *not* document net idmap delete */
    324 
    325         d_printf(_("net idmap secret <DOMAIN>|alloc <secret>\n"
    326                    "    Set the secret for the specified DOMAIN (or the alloc "
    327                    "module)\n"));
    328 
    329         return -1;
     539static int net_idmap_check(struct net_context *c, int argc, const char **argv)
     540{
     541        const char* dbfile;
     542        struct check_options opts;
     543
     544        if ( argc > 1 || c->display_usage) {
     545                d_printf("%s\n%s",
     546                         _("Usage:"),
     547                         _("net idmap check  [-v] [-r] [-a] [-T] [-f] [-l] [[--db=]<TDB>]\n"
     548                           "  Check an idmap database.\n"
     549                           "    --verbose,-v\tverbose\n"
     550                           "    --repair,-r\trepair\n"
     551                           "    --auto,-a\tnoninteractive mode\n"
     552                           "    --test,-T\tdry run\n"
     553                           "    --fore,-f\tforce\n"
     554                           "    --lock,-l\tlock db while doing the check\n"
     555                           "    TDB\tidmap database\n"));
     556                return c->display_usage ? 0 : -1;
     557        }
     558
     559        dbfile = (argc > 0) ? argv[0] : net_idmap_dbfile(c);
     560        if (dbfile == NULL) {
     561                return -1;
     562        }
     563        d_fprintf(stderr, _("check database: %s\n"), dbfile);
     564
     565        opts = (struct check_options) {
     566                .lock = c->opt_lock || c->opt_long_list_entries,
     567                .test = c->opt_testmode,
     568                .automatic = c->opt_auto,
     569                .verbose = c->opt_verbose,
     570                .force = c->opt_force,
     571                .repair = c->opt_repair || c->opt_reboot,
     572        };
     573
     574        return net_idmap_check_db(dbfile, &opts);
    330575}
    331576
     
    334579        TALLOC_CTX *mem_ctx;
    335580        int result = -1;
    336         DOM_SID src_sid, dst_sid;
     581        struct dom_sid src_sid, dst_sid;
    337582        char *src, *dst;
    338583        struct db_context *db;
     
    428673                        net_idmap_delete,
    429674                        NET_TRANSPORT_LOCAL,
    430                         N_("Not implemented yet"),
    431                         N_("net idmap delete\n"
    432                            "  Not implemented yet")
     675                        N_("Delete ID mapping"),
     676                        N_("net idmap delete <ID>\n"
     677                           "  Delete ID mapping")
    433678                },
    434679                {
     
    437682                        NET_TRANSPORT_LOCAL,
    438683                        N_("Set secret for specified domain"),
    439                         N_("net idmap secret {<DOMAIN>|alloc} <secret>\n"
    440                            "  Set secret for specified domain or alloc module")
     684                        N_("net idmap secret <DOMAIN> <secret>\n"
     685                           "  Set secret for specified domain")
    441686                },
    442687                {
     
    448693                           "  Set acl map")
    449694                },
     695                {
     696                        "check",
     697                        net_idmap_check,
     698                        NET_TRANSPORT_LOCAL,
     699                        N_("Check id mappings"),
     700                        N_("net idmap check\n"
     701                           "  Check id mappings")
     702                },
    450703                {NULL, NULL, 0, NULL, NULL}
    451704        };
Note: See TracChangeset for help on using the changeset viewer.