static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; /* Send request */ wbc_status = wbcStringToSid(sid_str, &sid); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } wbc_status = wbcSetGidMapping(gid, &sid); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } /* Display response */ d_printf("gid %d now mapped to sid %s\n", gid, sid_str); return true; }
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(_("Usage:\n" "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")); return -1; } ctx = talloc_new(NULL); ALLOC_CHECK(ctx); if (argc == 1) { input = fopen(argv[0], "r"); } else { input = stdin; } while (!feof(input)) { char line[128], sid_string[128]; int len; struct wbcDomainSid sid; enum id_type type = ID_TYPE_NOT_SPECIFIED; unsigned long idval; wbcErr wbc_status; if (fgets(line, 127, input) == NULL) break; len = strlen(line); if ( (len > 0) && (line[len-1] == '\n') ) line[len-1] = '\0'; if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2) { type = ID_TYPE_GID; } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2) { type = ID_TYPE_UID; } else if (sscanf(line, "USER HWM %lu", &idval) == 1) { /* set uid hwm */ wbc_status = wbcSetUidHwm(idval); if (!WBC_ERROR_IS_OK(wbc_status)) { d_fprintf(stderr, _("Could not set USER HWM: %s\n"), wbcErrorString(wbc_status)); } continue; } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) { /* set gid hwm */ wbc_status = wbcSetGidHwm(idval); if (!WBC_ERROR_IS_OK(wbc_status)) { d_fprintf(stderr, _("Could not set GROUP HWM: %s\n"), wbcErrorString(wbc_status)); } continue; } else { 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"), sid_string, wbcErrorString(wbc_status)); continue; } if (type == ID_TYPE_UID) { wbc_status = wbcSetUidMapping(idval, &sid); } else { 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"), (type == ID_TYPE_GID) ? "GID" : "UID", idval, sid_string, wbcErrorString(wbc_status)); continue; } } if (input != stdin) { fclose(input); } talloc_free(ctx); return 0; }