wbinfo.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,244 行 · 第 1/2 页
C
1,244 行
/* Unix SMB/CIFS implementation. Winbind status program. Copyright (C) Tim Potter 2000-2003 Copyright (C) Andrew Bartlett 2002 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 2 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "includes.h"#include "winbindd.h"#include "debug.h"#undef DBGC_CLASS#define DBGC_CLASS DBGC_WINBINDextern 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(); } 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(); } 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(); } 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;}/* 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)[i]); SAFE_FREE(response.extra_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 = response.extra_data; for (i = 0; i < response.data.num_entries; i++) { d_printf("%s\n", s); s += strlen(s) + 1; } SAFE_FREE(response.extra_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) d_printf("%s", (char *)response.extra_data); SAFE_FREE(response.extra_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(void){ struct winbindd_response response; ZERO_STRUCT(response); /* Send request */ if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM, NULL, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ if (response.extra_data) { const char *extra_data = (char *)response.extra_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); } 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) { char *extra_data = (char *)response.extra_data; d_printf("%s", extra_data); SAFE_FREE(response.extra_data); } return True;}/* Show domain info */static BOOL wbinfo_domain_info(const char *domain_name){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); fstrcpy(request.domain_name, domain_name); /* Send request */ if (winbindd_request_response(WINBINDD_DOMAIN_INFO, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("Name : %s\n", response.data.domain_info.name); d_printf("Alt_Name : %s\n", response.data.domain_info.alt_name); d_printf("SID : %s\n", response.data.domain_info.sid); d_printf("Active Directory : %s\n", response.data.domain_info.active_directory ? "Yes" : "No"); d_printf("Native : %s\n", response.data.domain_info.native_mode ? "Yes" : "No"); d_printf("Primary : %s\n", response.data.domain_info.primary ? "Yes" : "No"); d_printf("Sequence : %d\n", response.data.domain_info.sequence_number); return True;}/* Get a foreign DC's name */static BOOL wbinfo_getdcname(const char *domain_name){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); fstrcpy(request.domain_name, domain_name); /* Send request */ if (winbindd_request_response(WINBINDD_GETDCNAME, &request, &response) != NSS_STATUS_SUCCESS) { d_fprintf(stderr, "Could not get dc name for %s\n", domain_name); return False; } /* Display response */ d_printf("%s\n", response.data.dc_name); return True;}/* Check trust account password */static BOOL wbinfo_check_secret(void){ struct winbindd_response response; NSS_STATUS result; ZERO_STRUCT(response); result = winbindd_request_response(WINBINDD_CHECK_MACHACC, NULL, &response); d_printf("checking the trust secret via RPC calls %s\n", (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed"); if (result != NSS_STATUS_SUCCESS) d_fprintf(stderr, "error code was %s (0x%x)\n", response.data.auth.nt_status_string, response.data.auth.nt_status); return result == NSS_STATUS_SUCCESS; }/* Convert uid to sid */static BOOL wbinfo_uid_to_sid(uid_t uid){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ request.data.uid = uid; if (winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("%s\n", response.data.sid.sid); return True;}/* Convert gid to sid */static BOOL wbinfo_gid_to_sid(gid_t gid){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ request.data.gid = gid; if (winbindd_request_response(WINBINDD_GID_TO_SID, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("%s\n", response.data.sid.sid); return True;}/* Convert sid to uid */static BOOL wbinfo_sid_to_uid(char *sid){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.sid, sid); if (winbindd_request_response(WINBINDD_SID_TO_UID, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("%d\n", (int)response.data.uid); return True;}static BOOL wbinfo_sid_to_gid(char *sid){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send request */ fstrcpy(request.data.sid, sid); if (winbindd_request_response(WINBINDD_SID_TO_GID, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("%d\n", (int)response.data.gid); return True;}static BOOL wbinfo_allocate_rid(void){ uint32 rid; if (!winbind_allocate_rid(&rid)) return False; d_printf("New rid: %d\n", rid); return True;}/* Convert sid to string */static BOOL wbinfo_lookupsid(char *sid){ struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); /* Send off request */ fstrcpy(request.data.sid, sid); if (winbindd_request_response(WINBINDD_LOOKUPSID, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("%s%c%s %d\n", response.data.name.dom_name, winbind_separator(), response.data.name.name, response.data.name.type); return True;}/* Convert string to sid */static BOOL wbinfo_lookupname(char *name){ struct winbindd_request request; struct winbindd_response response; /* Send off request */ ZERO_STRUCT(request); ZERO_STRUCT(response); parse_wbinfo_domain_user(name, request.data.name.dom_name, request.data.name.name); if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) != NSS_STATUS_SUCCESS) return False; /* Display response */ d_printf("%s %s (%d)\n", response.data.sid.sid, sid_type_lookup(response.data.sid.type), response.data.sid.type); return True;}/* Authenticate a user with a plaintext password */static BOOL wbinfo_auth(char *username){ struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; char *p; /* Send off request */ ZERO_STRUCT(request); ZERO_STRUCT(response); p = strchr(username, '%'); if (p) { *p = 0; fstrcpy(request.data.auth.user, username); fstrcpy(request.data.auth.pass, p + 1); *p = '%'; } else fstrcpy(request.data.auth.user, username); result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response); /* Display response */ d_printf("plaintext 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;}/* Authenticate a user with a challenge/response */static BOOL wbinfo_auth_crap(char *username){ struct winbindd_request request;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?