mirror of
https://github.com/samba-team/samba.git
synced 2025-02-24 13:57:43 +03:00
Fix --set-auth-user command to delete entries from the secrets file when an
empty username/password is passed on the command line. Previously we were leaving the domain name set and the password set to a NULL character. Added a --get-auth-user command to display the restrict anonymous username information. Can only be run successfully by root. (This used to be commit dcaf21efc5b48ddb0cbe70ce17e45c035ef525ad)
This commit is contained in:
parent
d759a02094
commit
aea57af3e3
@ -588,21 +588,73 @@ static BOOL wbinfo_set_auth_user(char *username)
|
|||||||
} else
|
} else
|
||||||
password = "";
|
password = "";
|
||||||
|
|
||||||
/* Store in secrets.tdb */
|
/* Store or remove DOMAIN\username%password in secrets.tdb */
|
||||||
|
|
||||||
if (!secrets_store(SECRETS_AUTH_USER, user,
|
secrets_init();
|
||||||
strlen(user) + 1) ||
|
|
||||||
!secrets_store(SECRETS_AUTH_DOMAIN, domain,
|
if (user[0]) {
|
||||||
strlen(domain) + 1) ||
|
|
||||||
!secrets_store(SECRETS_AUTH_PASSWORD, password,
|
if (!secrets_store(SECRETS_AUTH_USER, user,
|
||||||
strlen(password) + 1)) {
|
strlen(user) + 1)) {
|
||||||
d_fprintf(stderr, "error storing authenticated user info\n");
|
d_fprintf(stderr, "error storing username\n");
|
||||||
return False;
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We always have a domain name added by the
|
||||||
|
parse_wbinfo_domain_user() function. */
|
||||||
|
|
||||||
|
if (!secrets_store(SECRETS_AUTH_DOMAIN, domain,
|
||||||
|
strlen(domain) + 1)) {
|
||||||
|
d_fprintf(stderr, "error storing domain name\n");
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
secrets_delete(SECRETS_AUTH_USER);
|
||||||
|
secrets_delete(SECRETS_AUTH_DOMAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (password[0]) {
|
||||||
|
|
||||||
|
if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
|
||||||
|
strlen(password) + 1)) {
|
||||||
|
d_fprintf(stderr, "error storing password\n");
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
secrets_delete(SECRETS_AUTH_PASSWORD);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wbinfo_get_auth_user(void)
|
||||||
|
{
|
||||||
|
char *user, *domain, *password;
|
||||||
|
|
||||||
|
/* Lift data from secrets file */
|
||||||
|
|
||||||
|
secrets_init();
|
||||||
|
|
||||||
|
user = secrets_fetch(SECRETS_AUTH_USER, NULL);
|
||||||
|
domain = secrets_fetch(SECRETS_AUTH_DOMAIN, NULL);
|
||||||
|
password = secrets_fetch(SECRETS_AUTH_PASSWORD, NULL);
|
||||||
|
|
||||||
|
if (!user && !domain && !password) {
|
||||||
|
d_printf("No authorised user configured\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pretty print authorised user info */
|
||||||
|
|
||||||
|
d_printf("%s%s%s%s%s\n", domain ? domain : "", domain ? "\\" : "",
|
||||||
|
user, password ? "%" : "", password ? password : "");
|
||||||
|
|
||||||
|
SAFE_FREE(user);
|
||||||
|
SAFE_FREE(domain);
|
||||||
|
SAFE_FREE(password);
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL wbinfo_ping(void)
|
static BOOL wbinfo_ping(void)
|
||||||
{
|
{
|
||||||
NSS_STATUS result;
|
NSS_STATUS result;
|
||||||
@ -621,6 +673,7 @@ static BOOL wbinfo_ping(void)
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
OPT_SET_AUTH_USER = 1000,
|
OPT_SET_AUTH_USER = 1000,
|
||||||
|
OPT_GET_AUTH_USER,
|
||||||
OPT_SEQUENCE
|
OPT_SEQUENCE
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -657,6 +710,7 @@ int main(int argc, char **argv)
|
|||||||
{ "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
|
{ "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
|
||||||
{ "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
|
{ "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
|
||||||
{ "set-auth-user", 'A', POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
|
{ "set-auth-user", 'A', POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
|
||||||
|
{ "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
|
||||||
{ "ping", 'p', POPT_ARG_NONE, 0, 'p', "'ping' winbindd to see if it is alive" },
|
{ "ping", 'p', POPT_ARG_NONE, 0, 'p', "'ping' winbindd to see if it is alive" },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
@ -821,8 +875,10 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OPT_SET_AUTH_USER:
|
case OPT_SET_AUTH_USER:
|
||||||
if (!(wbinfo_set_auth_user(string_arg)))
|
wbinfo_set_auth_user(string_arg);
|
||||||
goto done;
|
break;
|
||||||
|
case OPT_GET_AUTH_USER:
|
||||||
|
wbinfo_get_auth_user();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
d_fprintf(stderr, "Invalid option\n");
|
d_fprintf(stderr, "Invalid option\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user