summaryrefslogtreecommitdiff
path: root/source3/nsswitch/wbinfo.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-01-10 10:23:54 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-01-10 10:23:54 +0000
commitcf00e41421793d042f24d0b0ecf47237a3cfc7c2 (patch)
tree89a8d82ec580aa5ba670dc933388682a95239a2a /source3/nsswitch/wbinfo.c
parent692215e4858cb4ac14af58f7e9422c2b15c999b4 (diff)
downloadsamba-cf00e41421793d042f24d0b0ecf47237a3cfc7c2.tar.gz
samba-cf00e41421793d042f24d0b0ecf47237a3cfc7c2.tar.bz2
samba-cf00e41421793d042f24d0b0ecf47237a3cfc7c2.zip
This changes the winbind protcol a bit:
It adds a 'ping' request, just to check winbind is in fact alive It also changes winbindd_pam_auth_crap to take usernames and domain seperatly. (backward incompatible change, needs merge to 2.2, but this is not yet released code, so no workarounds) Finally, it adds some debugs and fixes a few memory leaks (uses talloc to do it). Andrew Bartlett (This used to be commit 6df29bfe335144a968f5367f624ef2b4cf9e69b0)
Diffstat (limited to 'source3/nsswitch/wbinfo.c')
-rw-r--r--source3/nsswitch/wbinfo.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/source3/nsswitch/wbinfo.c b/source3/nsswitch/wbinfo.c
index 9c012eb85d..56cccee3b8 100644
--- a/source3/nsswitch/wbinfo.c
+++ b/source3/nsswitch/wbinfo.c
@@ -31,6 +31,23 @@ NSS_STATUS winbindd_request(int req_type,
struct winbindd_request *request,
struct winbindd_response *response);
+/* 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_domain_user(const char *domuser, fstring domain, fstring user)
+{
+ char *p = strchr(domuser,*lp_winbind_separator());
+
+ if (!p)
+ return False;
+
+ fstrcpy(user, p+1);
+ fstrcpy(domain, domuser);
+ domain[PTR_DIFF(p, domuser)] = 0;
+ strupper(domain);
+ return True;
+}
+
/* List groups a user is a member of */
static BOOL wbinfo_get_usergroups(char *user)
@@ -282,8 +299,10 @@ static BOOL wbinfo_auth(char *username)
* Don't do the lookup if the name has no separator.
*/
- if (!strchr(username, *lp_winbind_separator()))
+ if (!strchr(username, *lp_winbind_separator())) {
+ printf("no domain seperator (%s) in username - failing\n", lp_winbind_separator());
return False;
+ }
/* Send off request */
@@ -317,6 +336,8 @@ static BOOL wbinfo_auth_crap(char *username)
struct winbindd_request request;
struct winbindd_response response;
NSS_STATUS result;
+ fstring name_user;
+ fstring name_domain;
fstring pass;
char *p;
@@ -324,8 +345,10 @@ static BOOL wbinfo_auth_crap(char *username)
* Don't do the lookup if the name has no separator.
*/
- if (!strchr(username, *lp_winbind_separator()))
+ if (!strchr(username, *lp_winbind_separator())) {
+ printf("no domain seperator (%s) in username - failing\n", lp_winbind_separator());
return False;
+ }
/* Send off request */
@@ -336,11 +359,14 @@ static BOOL wbinfo_auth_crap(char *username)
if (p) {
*p = 0;
- fstrcpy(request.data.auth_crap.user, username);
fstrcpy(pass, p + 1);
- *p = '%';
- } else
- fstrcpy(request.data.auth_crap.user, username);
+ }
+
+ parse_domain_user(username, name_domain, name_user);
+
+ fstrcpy(request.data.auth_crap.user, name_user);
+
+ fstrcpy(request.data.auth_crap.domain, name_domain);
generate_random_buffer(request.data.auth_crap.chal, 8, False);
@@ -447,6 +473,20 @@ static BOOL wbinfo_set_auth_user(char *username)
return True;
}
+static BOOL wbinfo_ping(void)
+{
+ NSS_STATUS result;
+
+ result = winbindd_request(WINBINDD_PING, NULL, NULL);
+
+ /* Display response */
+
+ printf("'ping' to winbindd %s\n",
+ (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
+
+ return result == NSS_STATUS_SUCCESS;
+}
+
/* Print program usage */
static void usage(void)
@@ -465,6 +505,7 @@ static void usage(void)
printf("\t-m\t\t\tlist trusted domains\n");
printf("\t-r user\t\t\tget user groups\n");
printf("\t-a user%%password\tauthenticate user\n");
+ printf("\t-p 'ping' winbindd to see if it is alive\n");
}
/* Main program */
@@ -500,6 +541,7 @@ int main(int argc, char **argv)
{ "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r' },
{ "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a' },
{ "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER },
+ { "ping", 'p', POPT_ARG_NONE, 0, 'p' },
{ 0, 0, 0, 0 }
};
@@ -640,6 +682,14 @@ int main(int argc, char **argv)
return 1;
break;
}
+ case 'p': {
+
+ if (!wbinfo_ping()) {
+ printf("could not ping winbindd!\n");
+ return 1;
+ }
+ break;
+ }
case OPT_SET_AUTH_USER:
if (!(wbinfo_set_auth_user(string_arg))) {
return 1;