📄 wbinfo.c
字号:
data_blob_free(&lm_response); } else { if (lp_client_lanman_auth(lp_ctx) && SMBencrypt(pass, request.data.auth_crap.chal, (unsigned char *)request.data.auth_crap.lm_resp)) { request.data.auth_crap.lm_resp_len = 24; } else { request.data.auth_crap.lm_resp_len = 0; } SMBNTencrypt(pass, request.data.auth_crap.chal, (unsigned char *)request.data.auth_crap.nt_resp); request.data.auth_crap.nt_resp_len = 24; } result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response); /* Display response */ d_printf("challenge/response password authentication %s\n", (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed"); if (response.data.auth.nt_status) d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n", response.data.auth.nt_status_string, response.data.auth.nt_status, response.data.auth.error_string); return result == NSS_STATUS_SUCCESS;}/* Print domain users */static bool print_domain_users(const char *domain){ struct winbindd_request request; struct winbindd_response response; const char *extra_data; fstring name; /* Send request to winbind daemon */ ZERO_STRUCT(request); ZERO_STRUCT(response); if (domain) { /* '.' is the special sign for our own domain */ if ( strequal(domain, ".") ) fstrcpy( request.domain_name, get_winbind_domain() ); else fstrcpy( request.domain_name, domain ); } if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) != NSS_STATUS_SUCCESS) return false; /* Look through extra data */ if (!response.extra_data.data) return false; extra_data = (const char *)response.extra_data.data; while(next_token(&extra_data, name, ",", sizeof(fstring))) d_printf("%s\n", name); SAFE_FREE(response.extra_data.data); return true;}/* Print domain groups */static bool print_domain_groups(const char *domain){ struct winbindd_request request; struct winbindd_response response; const char *extra_data; fstring name; ZERO_STRUCT(request); ZERO_STRUCT(response); if (domain) { if ( strequal(domain, ".") ) fstrcpy( request.domain_name, get_winbind_domain() ); else fstrcpy( request.domain_name, domain ); } if (winbindd_request_response(WINBINDD_LIST_GROUPS, &request, &response) != NSS_STATUS_SUCCESS) return false; /* Look through extra data */ if (!response.extra_data.data) return false; extra_data = (const char *)response.extra_data.data; while(next_token(&extra_data, name, ",", sizeof(fstring))) d_printf("%s\n", name); SAFE_FREE(response.extra_data.data); return true;}static bool wbinfo_ping(void){ NSS_STATUS result; result = winbindd_request_response(WINBINDD_PING, NULL, NULL); /* Display response */ d_printf("Ping to winbindd %s on fd %d\n", (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", winbindd_fd); return result == NSS_STATUS_SUCCESS;}/* Main program */enum { OPT_SET_AUTH_USER = 1000, OPT_GET_AUTH_USER, OPT_DOMAIN_NAME, OPT_SEQUENCE, OPT_GETDCNAME, OPT_USERDOMGROUPS, OPT_USERSIDS, OPT_ALLOCATE_UID, OPT_ALLOCATE_GID, OPT_SEPARATOR, OPT_LIST_ALL_DOMAINS, OPT_LIST_OWN_DOMAIN, OPT_UID_INFO, OPT_GROUP_INFO,};int main(int argc, char **argv, char **envp){ int opt; poptContext pc; static char *string_arg; static char *opt_domain_name; static int int_arg; int result = 1; struct poptOption long_options[] = { POPT_AUTOHELP /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"}, { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" }, { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" }, { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" }, { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" }, { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" }, { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" }, { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" }, { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" }, { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" }, { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" }, { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" }, { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" }, { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" }, { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" }, { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" }, { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" }, { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" }, { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" }, { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" }, { "user-domgroups", 0, POPT_ARG_STRING, &string_arg, OPT_USERDOMGROUPS, "Get user domain groups", "SID" }, { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" }, { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" }, { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME, "Get a DC name for a foreign domain", "domainname" }, { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" }, { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },#ifdef HAVE_KRB5 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" }, /* destroys wbinfo --help output */ /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */#endif { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL }, POPT_COMMON_VERSION POPT_COMMON_SAMBA POPT_TABLEEND }; /* Parse options */ pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0); /* Parse command line options */ if (argc == 1) { poptPrintHelp(pc, stderr, 0); return 1; } while((opt = poptGetNextOpt(pc)) != -1) { /* get the generic configuration parameters like --domain */ } poptFreeContext(pc); pc = poptGetContext(NULL, argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'u': if (!print_domain_users(opt_domain_name)) { d_fprintf(stderr, "Error looking up domain users\n"); goto done; } break; case 'g': if (!print_domain_groups(opt_domain_name)) { d_fprintf(stderr, "Error looking up domain groups\n"); goto done; } break; case 's': if (!wbinfo_lookupsid(string_arg)) { d_fprintf(stderr, "Could not lookup sid %s\n", string_arg); goto done; } break; case 'n': if (!wbinfo_lookupname(string_arg)) { d_fprintf(stderr, "Could not lookup name %s\n", string_arg); goto done; } break; case 'N': if (!wbinfo_wins_byname(string_arg)) { d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg); goto done; } break; case 'I': if (!wbinfo_wins_byip(string_arg)) { d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg); goto done; } break; case 'U': if (!wbinfo_uid_to_sid(int_arg)) { d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg); goto done; } break; case 'G': if (!wbinfo_gid_to_sid(int_arg)) { d_fprintf(stderr, "Could not convert gid %d to sid\n", int_arg); goto done; } break; case 'S': if (!wbinfo_sid_to_uid(string_arg)) { d_fprintf(stderr, "Could not convert sid %s to uid\n", string_arg); goto done; } break; case 'Y': if (!wbinfo_sid_to_gid(string_arg)) { d_fprintf(stderr, "Could not convert sid %s to gid\n", string_arg); goto done; } break; case 't': if (!wbinfo_check_secret()) { d_fprintf(stderr, "Could not check secret\n"); goto done; } break; case 'm': if (!wbinfo_list_domains(false)) { d_fprintf(stderr, "Could not list trusted domains\n"); goto done; } break; case OPT_SEQUENCE: if (!wbinfo_show_sequence(opt_domain_name)) { d_fprintf(stderr, "Could not show sequence numbers\n"); goto done; } break; case 'D': if (!wbinfo_domain_info(string_arg)) { d_fprintf(stderr, "Could not get domain info\n"); goto done; } break; case 'i': if (!wbinfo_get_userinfo(string_arg)) { d_fprintf(stderr, "Could not get info for user %s\n", string_arg); goto done; } break; case OPT_UID_INFO: if ( !wbinfo_get_uidinfo(int_arg)) { d_fprintf(stderr, "Could not get info for uid " "%d\n", int_arg); goto done; } break; case OPT_GROUP_INFO: if ( !wbinfo_get_groupinfo(string_arg)) { d_fprintf(stderr, "Could not get info for " "group %s\n", string_arg); goto done; } break; case 'r': if (!wbinfo_get_usergroups(string_arg)) { d_fprintf(stderr, "Could not get groups for user %s\n", string_arg); goto done; } break; case OPT_USERSIDS: if (!wbinfo_get_usersids(string_arg)) { d_fprintf(stderr, "Could not get group SIDs for user SID %s\n", string_arg); goto done; } break; case OPT_USERDOMGROUPS: if (!wbinfo_get_userdomgroups(string_arg)) { d_fprintf(stderr, "Could not get user's domain groups " "for user SID %s\n", string_arg); goto done; } break; case 'a': { bool got_error = false; if (!wbinfo_auth(string_arg)) { d_fprintf(stderr, "Could not authenticate user %s with " "plaintext password\n", string_arg); got_error = true; } if (!wbinfo_auth_crap(cmdline_lp_ctx, string_arg)) { d_fprintf(stderr, "Could not authenticate user %s with " "challenge/response\n", string_arg); got_error = true; } if (got_error) goto done; break; } case 'K': { uint32_t flags = WBFLAG_PAM_KRB5 | WBFLAG_PAM_CACHED_LOGIN | WBFLAG_PAM_FALLBACK_AFTER_KRB5 | WBFLAG_PAM_INFO3_TEXT; if (!wbinfo_auth_krb5(string_arg, "FILE", flags)) { d_fprintf(stderr, "Could not authenticate user [%s] with " "Kerberos (ccache: %s)\n", string_arg, "FILE"); goto done; } break; } case 'p': if (!wbinfo_ping()) { d_fprintf(stderr, "could not ping winbindd!\n"); goto done; } break; case OPT_GETDCNAME: if (!wbinfo_getdcname(string_arg)) { goto done; } break; case OPT_SEPARATOR: { const char sep = winbind_separator_int(true); if ( !sep ) { goto done; } d_printf("%c\n", sep); break; } case OPT_LIST_ALL_DOMAINS: if (!wbinfo_list_domains(true)) { goto done; } break; case OPT_LIST_OWN_DOMAIN: if (!wbinfo_list_own_domain()) { goto done; } break; /* generic configuration options */ case OPT_DOMAIN_NAME: break; default: d_fprintf(stderr, "Invalid option\n"); poptPrintHelp(pc, stderr, 0); goto done; } } result = 0; /* Exit code */ done: poptFreeContext(pc); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -