📄 wbinfo.c
字号:
/* Unix SMB/CIFS implementation. Winbind status program. Copyright (C) Tim Potter 2000-2003 Copyright (C) Andrew Bartlett 2002-2007 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/>.*/#include "includes.h"#include "pstring.h"#include "winbind_client.h"#include "librpc/gen_ndr/ndr_netlogon.h"#include "libcli/auth/libcli_auth.h"#include "libcli/security/security.h"#include "lib/cmdline/popt_common.h"#include "dynconfig/dynconfig.h"#include "param/param.h"extern int winbindd_fd;static char winbind_separator_int(bool strict){ struct winbindd_response response; static bool got_sep; static char sep; if (got_sep) return sep; ZERO_STRUCT(response); /* Send off request */ if (winbindd_request_response(WINBINDD_INFO, NULL, &response) != NSS_STATUS_SUCCESS) { d_fprintf(stderr, "could not obtain winbind separator!\n"); if (strict) { return 0; } /* HACK: (this module should not call lp_ funtions) */ return *lp_winbind_separator(cmdline_lp_ctx); } sep = response.data.info.winbind_separator; got_sep = true; if (!sep) { d_fprintf(stderr, "winbind separator was NULL!\n"); if (strict) { return 0; } /* HACK: (this module should not call lp_ funtions) */ sep = *lp_winbind_separator(cmdline_lp_ctx); } return sep;}static char winbind_separator(void){ return winbind_separator_int(false);}static const char *get_winbind_domain(void){ struct winbindd_response response; static fstring winbind_domain; ZERO_STRUCT(response); /* Send off request */ if (winbindd_request_response(WINBINDD_DOMAIN_NAME, NULL, &response) != NSS_STATUS_SUCCESS) { d_fprintf(stderr, "could not obtain winbind domain name!\n"); /* HACK: (this module should not call lp_ funtions) */ return lp_workgroup(cmdline_lp_ctx); } fstrcpy(winbind_domain, response.data.domain_name); return winbind_domain;}/* Copy of parse_domain_user from winbindd_util.c. Parse a string of the form DOMAIN/user into a domain and a user */static bool parse_wbinfo_domain_user(const char *domuser, fstring domain, fstring user){ char *p = strchr(domuser,winbind_separator()); if (!p) { fstrcpy(user, domuser); fstrcpy(domain, get_winbind_domain()); return true; } fstrcpy(user, p+1); fstrcpy(domain, domuser); domain[PTR_DIFF(p, domuser)] = 0; strupper_m(domain); return true;}/* pull pwent info for a given user */static bool wbinfo_get_userinfo(char *user){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.username, user); result = winbindd_request_response(WINBINDD_GETPWNAM, &request, &response); if (result != NSS_STATUS_SUCCESS) return false; d_printf( "%s:%s:%d:%d:%s:%s:%s\n", response.data.pw.pw_name, response.data.pw.pw_passwd, response.data.pw.pw_uid, response.data.pw.pw_gid, response.data.pw.pw_gecos, response.data.pw.pw_dir, response.data.pw.pw_shell ); return true;}/* pull pwent info for a given uid */static bool wbinfo_get_uidinfo(int uid){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; ZERO_STRUCT(request); ZERO_STRUCT(response); request.data.uid = uid; result = winbindd_request_response(WINBINDD_GETPWUID, &request, &response); if (result != NSS_STATUS_SUCCESS) return false; d_printf( "%s:%s:%d:%d:%s:%s:%s\n", response.data.pw.pw_name, response.data.pw.pw_passwd, response.data.pw.pw_uid, response.data.pw.pw_gid, response.data.pw.pw_gecos, response.data.pw.pw_dir, response.data.pw.pw_shell ); return true;}/* pull grent for a given group */static bool wbinfo_get_groupinfo(char *group){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.groupname, group); result = winbindd_request_response(WINBINDD_GETGRNAM, &request, &response); if ( result != NSS_STATUS_SUCCESS) return false; d_printf( "%s:%s:%d\n", response.data.gr.gr_name, response.data.gr.gr_passwd, response.data.gr.gr_gid ); return true;}/* List groups a user is a member of */static bool wbinfo_get_usergroups(char *user){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; int i; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.username, user); result = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response); if (result != NSS_STATUS_SUCCESS) return false; for (i = 0; i < response.data.num_entries; i++) d_printf("%d\n", (int)((gid_t *)response.extra_data.data)[i]); SAFE_FREE(response.extra_data.data); return true;}/* List group SIDs a user SID is a member of */static bool wbinfo_get_usersids(char *user_sid){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; int i; const char *s; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.sid, user_sid); result = winbindd_request_response(WINBINDD_GETUSERSIDS, &request, &response); if (result != NSS_STATUS_SUCCESS) return false; s = (const char *)response.extra_data.data; for (i = 0; i < response.data.num_entries; i++) { d_printf("%s\n", s); s += strlen(s) + 1; } SAFE_FREE(response.extra_data.data); return true;}static bool wbinfo_get_userdomgroups(const char *user_sid){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.sid, user_sid); result = winbindd_request_response(WINBINDD_GETUSERDOMGROUPS, &request, &response); if (result != NSS_STATUS_SUCCESS) return false; if (response.data.num_entries != 0) printf("%s", (char *)response.extra_data.data); SAFE_FREE(response.extra_data.data); return true;}/* Convert NetBIOS name to IP */static bool wbinfo_wins_byname(char *name){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.winsreq, name); if (winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response) != NSS_STATUS_SUCCESS) { return false; } /* Display response */ d_printf("%s\n", response.data.winsresp); return true;}/* Convert IP to NetBIOS name */static bool wbinfo_wins_byip(char *ip){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.winsreq, ip); if (winbindd_request_response(WINBINDD_WINS_BYIP, &request, &response) != NSS_STATUS_SUCCESS) { return false; } /* Display response */ d_printf("%s\n", response.data.winsresp); return true;}/* List trusted domains */static bool wbinfo_list_domains(bool list_all_domains){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ request.data.list_all_domains = list_all_domains; if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM, &request, &response) != NSS_STATUS_SUCCESS) return false; /* Display response */ if (response.extra_data.data) { const char *extra_data = (char *)response.extra_data.data; fstring name; char *p; while(next_token(&extra_data, name, "\n", sizeof(fstring))) { p = strchr(name, '\\'); if (p == 0) { d_fprintf(stderr, "Got invalid response: %s\n", extra_data); return false; } *p = 0; d_printf("%s\n", name); } SAFE_FREE(response.extra_data.data); } return true;}/* List own domain */static bool wbinfo_list_own_domain(void){ d_printf("%s\n", get_winbind_domain()); return true;}/* show sequence numbers */static bool wbinfo_show_sequence(const char *domain){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(response); ZERO_STRUCT(request); if ( domain ) fstrcpy( request.domain_name, domain ); /* Send request */ if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE, &request, &response) != NSS_STATUS_SUCCESS) return false; /* Display response */ if (response.extra_data.data) { char *extra_data = (char *)response.extra_data.data; d_printf("%s", extra_data); SAFE_FREE(response.extra_data.data); } return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -