📄 net.c
字号:
d_printf("Machine account password change requires the -f flag.\n"); d_printf("Do NOT use this function unless you know what it does!\n"); d_printf("This function will change the ADS Domain member machine account password in the secrets.tdb file!\n"); } return 0;}static int net_share(int argc, const char **argv){ if (net_rpc_check(0)) return net_rpc_share(argc, argv); return net_rap_share(argc, argv);}static int net_file(int argc, const char **argv){ if (net_rpc_check(0)) return net_rpc_file(argc, argv); return net_rap_file(argc, argv);}/* Retrieve our local SID or the SID for the specified name */static int net_getlocalsid(int argc, const char **argv){ DOM_SID sid; const char *name; fstring sid_str; if (argc >= 1) { name = argv[0]; } else { name = global_myname(); } if(!initialize_password_db(False)) { DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n" "backend knowlege (such as the sid stored in LDAP)\n")); } /* first check to see if we can even access secrets, so we don't panic when we can't. */ if (!secrets_init()) { d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name); return 1; } /* Generate one, if it doesn't exist */ get_global_sam_sid(); if (!secrets_fetch_domain_sid(name, &sid)) { DEBUG(0, ("Can't fetch domain SID for name: %s\n", name)); return 1; } sid_to_string(sid_str, &sid); d_printf("SID for domain %s is: %s\n", name, sid_str); return 0;}static int net_setlocalsid(int argc, const char **argv){ DOM_SID sid; if ( (argc != 1) || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0) || (!string_to_sid(&sid, argv[0])) || (sid.num_auths != 4)) { d_printf("usage: net setlocalsid S-1-5-21-x-y-z\n"); return 1; } if (!secrets_store_domain_sid(global_myname(), &sid)) { DEBUG(0,("Can't store domain SID as a pdc/bdc.\n")); return 1; } return 0;}static int net_getdomainsid(int argc, const char **argv){ DOM_SID domain_sid; fstring sid_str; if(!initialize_password_db(False)) { DEBUG(0, ("WARNING: Could not open passdb - domain sid may not reflect passdb\n" "backend knowlege (such as the sid stored in LDAP)\n")); } /* Generate one, if it doesn't exist */ get_global_sam_sid(); if (!secrets_fetch_domain_sid(global_myname(), &domain_sid)) { d_fprintf(stderr, "Could not fetch local SID\n"); return 1; } sid_to_string(sid_str, &domain_sid); d_printf("SID for domain %s is: %s\n", global_myname(), sid_str); if (!secrets_fetch_domain_sid(opt_workgroup, &domain_sid)) { d_fprintf(stderr, "Could not fetch domain SID\n"); return 1; } sid_to_string(sid_str, &domain_sid); d_printf("SID for domain %s is: %s\n", opt_workgroup, sid_str); return 0;}#ifdef WITH_FAKE_KASERVERint net_help_afs(int argc, const char **argv){ d_printf(" net afs key filename\n" "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n"); d_printf(" net afs impersonate <user> <cell>\n" "\tCreates a token for user@cell\n\n"); return -1;}static int net_afs_key(int argc, const char **argv){ int fd; struct afs_keyfile keyfile; if (argc != 2) { d_printf("usage: 'net afs key <keyfile> cell'\n"); return -1; } if (!secrets_init()) { d_fprintf(stderr, "Could not open secrets.tdb\n"); return -1; } if ((fd = open(argv[0], O_RDONLY, 0)) < 0) { d_fprintf(stderr, "Could not open %s\n", argv[0]); return -1; } if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) { d_fprintf(stderr, "Could not read keyfile\n"); return -1; } if (!secrets_store_afs_keyfile(argv[1], &keyfile)) { d_fprintf(stderr, "Could not write keyfile to secrets.tdb\n"); return -1; } return 0;}static int net_afs_impersonate(int argc, const char **argv){ char *token; if (argc != 2) { fprintf(stderr, "Usage: net afs impersonate <user> <cell>\n"); exit(1); } token = afs_createtoken_str(argv[0], argv[1]); if (token == NULL) { fprintf(stderr, "Could not create token\n"); exit(1); } if (!afs_settoken_str(token)) { fprintf(stderr, "Could not set token into kernel\n"); exit(1); } printf("Success: %s@%s\n", argv[0], argv[1]); return 0;}static int net_afs(int argc, const char **argv){ struct functable func[] = { {"key", net_afs_key}, {"impersonate", net_afs_impersonate}, {"help", net_help_afs}, {NULL, NULL} }; return net_run_function(argc, argv, func, net_help_afs);}#endif /* WITH_FAKE_KASERVER */static BOOL search_maxrid(struct pdb_search *search, const char *type, uint32 *max_rid){ struct samr_displayentry *entries; uint32 i, num_entries; if (search == NULL) { d_fprintf(stderr, "get_maxrid: Could not search %s\n", type); return False; } num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries); for (i=0; i<num_entries; i++) *max_rid = MAX(*max_rid, entries[i].rid); pdb_search_destroy(search); return True;}static uint32 get_maxrid(void){ uint32 max_rid = 0; if (!search_maxrid(pdb_search_users(0), "users", &max_rid)) return 0; if (!search_maxrid(pdb_search_groups(), "groups", &max_rid)) return 0; if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()), "aliases", &max_rid)) return 0; return max_rid;}static int net_maxrid(int argc, const char **argv){ uint32 rid; if (argc != 0) { DEBUG(0, ("usage: net maxrid\n")); return 1; } if ((rid = get_maxrid()) == 0) { DEBUG(0, ("can't get current maximum rid\n")); return 1; } d_printf("Currently used maximum rid: %d\n", rid); return 0;}/* main function table */static struct functable net_func[] = { {"RPC", net_rpc}, {"RAP", net_rap}, {"ADS", net_ads}, /* eventually these should auto-choose the transport ... */ {"FILE", net_file}, {"SHARE", net_share}, {"SESSION", net_rap_session}, {"SERVER", net_rap_server}, {"DOMAIN", net_rap_domain}, {"PRINTQ", net_rap_printq}, {"USER", net_user}, {"GROUP", net_group}, {"GROUPMAP", net_groupmap}, {"VALIDATE", net_rap_validate}, {"GROUPMEMBER", net_rap_groupmember}, {"ADMIN", net_rap_admin}, {"SERVICE", net_rap_service}, {"PASSWORD", net_rap_password}, {"CHANGETRUSTPW", net_changetrustpw}, {"CHANGESECRETPW", net_changesecretpw}, {"TIME", net_time}, {"LOOKUP", net_lookup}, {"JOIN", net_join}, {"CACHE", net_cache}, {"GETLOCALSID", net_getlocalsid}, {"SETLOCALSID", net_setlocalsid}, {"GETDOMAINSID", net_getdomainsid}, {"MAXRID", net_maxrid}, {"IDMAP", net_idmap}, {"STATUS", net_status}, {"USERSIDLIST", net_usersidlist},#ifdef WITH_FAKE_KASERVER {"AFS", net_afs},#endif {"HELP", net_help}, {NULL, NULL}};/**************************************************************************** main program****************************************************************************/ int main(int argc, const char **argv){ int opt,i; char *p; int rc = 0; int argc_new = 0; const char ** argv_new; poptContext pc; struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, 'h'}, {"workgroup", 'w', POPT_ARG_STRING, &opt_target_workgroup}, {"user", 'U', POPT_ARG_STRING, &opt_user_name, 'U'}, {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'}, {"port", 'p', POPT_ARG_INT, &opt_port}, {"myname", 'n', POPT_ARG_STRING, &opt_requester_name}, {"server", 'S', POPT_ARG_STRING, &opt_host}, {"container", 'c', POPT_ARG_STRING, &opt_container}, {"comment", 'C', POPT_ARG_STRING, &opt_comment}, {"maxusers", 'M', POPT_ARG_INT, &opt_maxusers}, {"flags", 'F', POPT_ARG_INT, &opt_flags}, {"long", 'l', POPT_ARG_NONE, &opt_long_list_entries}, {"reboot", 'r', POPT_ARG_NONE, &opt_reboot}, {"force", 'f', POPT_ARG_NONE, &opt_force}, {"timeout", 't', POPT_ARG_INT, &opt_timeout}, {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass}, {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup}, {"verbose", 'v', POPT_ARG_NONE, &opt_verbose}, /* Options for 'net groupmap set' */ {"local", 'L', POPT_ARG_NONE, &opt_localgroup}, {"domain", 'D', POPT_ARG_NONE, &opt_domaingroup}, {"ntname", 'N', POPT_ARG_STRING, &opt_newntname}, {"rid", 'R', POPT_ARG_INT, &opt_rid}, /* Options for 'net rpc share migrate' */ {"acls", 0, POPT_ARG_NONE, &opt_acls}, {"attrs", 0, POPT_ARG_NONE, &opt_attrs}, {"timestamps", 0, POPT_ARG_NONE, &opt_timestamps}, {"exclude", 'e', POPT_ARG_STRING, &opt_exclude}, {"destination", 0, POPT_ARG_STRING, &opt_destination}, POPT_COMMON_SAMBA { 0, 0, 0, 0} }; zero_ip(&opt_dest_ip); load_case_tables(); /* set default debug level to 0 regardless of what smb.conf sets */ DEBUGLEVEL_CLASS[DBGC_ALL] = 0; dbf = x_stderr; pc = poptGetContext(NULL, argc, (const char **) argv, long_options, POPT_CONTEXT_KEEP_FIRST); while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'h': net_help(argc, argv); exit(0); break; case 'I': opt_dest_ip = *interpret_addr2(poptGetOptArg(pc)); if (is_zero_ip(opt_dest_ip)) d_fprintf(stderr, "\nInvalid ip address specified\n"); else opt_have_ip = True; break; case 'U': opt_user_specified = True; opt_user_name = SMB_STRDUP(opt_user_name); p = strchr(opt_user_name,'%'); if (p) { *p = 0; opt_password = p+1; } break; default: d_fprintf(stderr, "\nInvalid option %s: %s\n", poptBadOption(pc, 0), poptStrerror(opt)); net_help(argc, argv); exit(1); } } /* * Don't load debug level from smb.conf. It should be * set by cmdline arg or remain default (0) */ AllowDebugChange = False; lp_load(dyn_CONFIGFILE,True,False,False); argv_new = (const char **)poptGetArgs(pc); argc_new = argc; for (i=0; i<argc; i++) { if (argv_new[i] == NULL) { argc_new = i; break; } } if (opt_requester_name) { set_global_myname(opt_requester_name); } if (!opt_user_name && getenv("LOGNAME")) { opt_user_name = getenv("LOGNAME"); } if (!opt_workgroup) { opt_workgroup = smb_xstrdup(lp_workgroup()); } if (!opt_target_workgroup) { opt_target_workgroup = smb_xstrdup(lp_workgroup()); } if (!init_names()) exit(1); load_interfaces(); /* this makes sure that when we do things like call scripts, that it won't assert becouse we are not root */ sec_init(); if (opt_machine_pass) { /* it is very useful to be able to make ads queries as the machine account for testing purposes and for domain leave */ net_use_machine_password(); } if (!opt_password) { opt_password = getenv("PASSWD"); } rc = net_run_function(argc_new-1, argv_new+1, net_func, net_help); DEBUG(2,("return code = %d\n", rc)); return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -