2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/*
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher SSSD
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher proxy_id.c
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher Authors:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher Copyright (C) 2010 Red Hat
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher This program is free software; you can redistribute it and/or modify
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher it under the terms of the GNU General Public License as published by
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher (at your option) any later version.
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher This program is distributed in the hope that it will be useful,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher GNU General Public License for more details.
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher You should have received a copy of the GNU General Public License
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
f2c346eaa486431ffa2a3adc05356159de834e2eLukas Slebodnik#include "config.h"
f2c346eaa486431ffa2a3adc05356159de834e2eLukas Slebodnik
f2c346eaa486431ffa2a3adc05356159de834e2eLukas Slebodnik#include "util/sss_format.h"
580374daba2ab2c6075a7d0de9512abff133e2e9Jakub Hrozek#include "util/strtonum.h"
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher#include "providers/proxy/proxy.h"
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Getpwnam-wrapper======================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
29d85ae19933805622fdcead4ea43ba2d06cc3f0Lukas Slebodnikstatic int save_user(struct sss_domain_info *domain,
413aef1529fb3d5ed4d0f38e219f5456d7fe3ae0Fabiano Fidêncio struct passwd *pwd, const char *real_name,
2537fe318a3866780abca100cf6eb7c258f9d02bFabiano Fidêncio const char *alias);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekstatic int
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekhandle_getpw_result(enum nss_status status, struct passwd *pwd,
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek struct sss_domain_info *dom, bool *del_user);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kosstatic int
428f137041034362a1cc6b64d68011a1d3f67cd7Lukas Slebodnikdelete_user(struct sss_domain_info *domain,
3412d14d65490c32414e72ac20fe21bad53ceb45Simo Sorce const char *name, uid_t uid);
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos
7ff5374d0103f8e2e03ef15790838b85918153aeLukas Slebodnikstatic int get_pw_name(struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek const char *i_name)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct passwd *pwd;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *buffer;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher size_t buflen;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek uid_t uid;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek bool del_user;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek struct ldb_result *cached_pwd = NULL;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek const char *real_name = NULL;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *shortname_or_alias;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Searching user by name (%s)\n", i_name);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek tmpctx = talloc_new(NULL);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sss_parse_internal_fqname(tmpctx, i_name, &shortname_or_alias, NULL);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (ret != EOK) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher pwd = talloc_zero(tmpctx, struct passwd);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!pwd) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buflen = DEFAULT_BUFSIZE;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buffer = talloc_size(tmpctx, buflen);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher /* FIXME: should we move this call outside the transaction to keep the
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher * transaction as short as possible ? */
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek status = ctx->ops.getpwnam_r(shortname_or_alias, pwd, buffer, buflen, &ret);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = handle_getpw_result(status, pwd, dom, &del_user);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getpwnam failed [%d]: %s\n", ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (del_user) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = delete_user(dom, i_name, 0);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek uid = pwd->pw_uid;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* Canonicalize the username in case it was actually an alias */
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ctx->fast_alias == true) {
b3292840ebaa747a9fd596ff47cc5d18198361d0Michal Zidek ret = sysdb_getpwuid(tmpctx, dom, uid, &cached_pwd);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret != EOK) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek /* Non-fatal, attempt to canonicalize online */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Request to cache failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret == EOK && cached_pwd->count == 1) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek real_name = ldb_msg_find_attr_as_string(cached_pwd->msgs[0],
51773686d354b82081830444c048706d83d43d65Jakub Hrozek SYSDB_NAME, NULL);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (!real_name) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Cached user has no name?\n");
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (real_name == NULL) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek memset(buffer, 0, buflen);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek status = ctx->ops.getpwuid_r(uid, pwd, buffer, buflen, &ret);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek ret = handle_getpw_result(status, pwd, dom, &del_user);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getpwuid failed [%d]: %s\n", ret, strerror(ret));
51773686d354b82081830444c048706d83d43d65Jakub Hrozek goto done;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek real_name = sss_create_internal_fqname(tmpctx, pwd->pw_name, dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (real_name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = ENOMEM;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (del_user) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = delete_user(dom, i_name, uid);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* Both lookups went fine, we can save the user now */
2537fe318a3866780abca100cf6eb7c258f9d02bFabiano Fidêncio ret = save_user(dom, pwd, real_name, i_name);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekdone:
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek talloc_zfree(tmpctx);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "proxy -> getpwnam_r failed for '%s' <%d>: %s\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek i_name, ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return ret;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek}
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekstatic int
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekhandle_getpw_result(enum nss_status status, struct passwd *pwd,
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek struct sss_domain_info *dom, bool *del_user)
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek{
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek int ret = EOK;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (!del_user) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return EINVAL;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *del_user = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher switch (status) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case NSS_STATUS_NOTFOUND:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "User not found.\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *del_user = true;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case NSS_STATUS_SUCCESS:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "User found: (%s, %"SPRIuid", %"SPRIgid")\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov pwd->pw_name, pwd->pw_uid, pwd->pw_gid);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher /* uid=0 or gid=0 are invalid values */
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher /* also check that the id is in the valid range for this domain */
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (OUT_OF_ID_RANGE(pwd->pw_uid, dom->id_min, dom->id_max) ||
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher OUT_OF_ID_RANGE(pwd->pw_gid, dom->id_min, dom->id_max)) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User filtered out! (id out of range)\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *del_user = true;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case NSS_STATUS_UNAVAIL:
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Remote back end is not available. Entering offline mode\n");
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENXIO;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher default:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unknown return code %d\n", status);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = EIO;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kosstatic int
428f137041034362a1cc6b64d68011a1d3f67cd7Lukas Slebodnikdelete_user(struct sss_domain_info *domain,
3412d14d65490c32414e72ac20fe21bad53ceb45Simo Sorce const char *name, uid_t uid)
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos{
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos int ret = EOK;
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User %s does not exist (or is invalid) on remote server,"
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov " deleting!\n", name);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_delete_user(domain, name, uid);
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos if (ret == ENOENT) {
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos ret = EOK;
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos }
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos return ret;
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos}
9579839a00493830c10a856ad1f5e035b6fa3b45Ondrej Kos
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidênciostatic int
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncioprepare_attrs_for_saving_ops(TALLOC_CTX *mem_ctx,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio bool case_sensitive,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *real_name, /* already_qualified */
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *alias, /* already qualified */
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio struct sysdb_attrs **attrs)
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek{
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *lc_name = NULL;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *cased_alias = NULL;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek errno_t ret;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (!case_sensitive || alias != NULL) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (*attrs == NULL) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio *attrs = sysdb_new_attrs(mem_ctx);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (*attrs == NULL) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Allocation error ?!\n");
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio ret = ENOMEM;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio goto done;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (!case_sensitive) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio lc_name = sss_tc_utf8_str_tolower(*attrs, real_name);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (lc_name == NULL) {
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek DEBUG(SSSDBG_OP_FAILURE, "Cannot convert name to lowercase.\n");
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek ret = ENOMEM;
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek goto done;
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek }
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio ret = sysdb_attrs_add_string(*attrs, SYSDB_NAME_ALIAS, lc_name);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek ret = ENOMEM;
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek goto done;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (alias != NULL) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio cased_alias = sss_get_cased_name(*attrs, alias, case_sensitive);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (cased_alias == NULL) {
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek ret = ENOMEM;
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek /* Add the alias only if it differs from lowercased pw_name */
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (lc_name == NULL || strcmp(cased_alias, lc_name) != 0) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio ret = sysdb_attrs_add_string(*attrs, SYSDB_NAME_ALIAS,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio cased_alias);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (ret != EOK) {
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek DEBUG(SSSDBG_OP_FAILURE, "Could not add name alias\n");
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek goto done;
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio ret = EOK;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidênciodone:
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio return ret;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio}
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidênciostatic int save_user(struct sss_domain_info *domain,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio struct passwd *pwd,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *real_name, /* already qualified */
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *alias) /* already qualified */
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio{
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *shell;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio const char *gecos;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio struct sysdb_attrs *attrs = NULL;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio errno_t ret;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (pwd->pw_shell && pwd->pw_shell[0] != '\0') {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio shell = pwd->pw_shell;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio } else {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio shell = NULL;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio }
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (pwd->pw_gecos && pwd->pw_gecos[0] != '\0') {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio gecos = pwd->pw_gecos;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio } else {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio gecos = NULL;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio }
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio ret = prepare_attrs_for_saving_ops(NULL, domain->case_sensitive,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio real_name, alias, &attrs);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (ret != EOK) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio goto done;
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio }
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_store_user(domain,
51773686d354b82081830444c048706d83d43d65Jakub Hrozek real_name,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek pwd->pw_passwd,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek pwd->pw_uid,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek pwd->pw_gid,
01d048293cba60cf45ca2791585a7d6dc3bf57b2Jakub Hrozek gecos,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek pwd->pw_dir,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek shell,
8455d5ab61184e0d126fc074a9ce6e98391eb909Jakub Hrozek NULL,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek attrs,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek NULL,
2537fe318a3866780abca100cf6eb7c258f9d02bFabiano Fidêncio domain->user_timeout,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek 0);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not add user to cache\n");
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek goto done;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidekdone:
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek talloc_zfree(attrs);
22e074249928605a1d5b926274ae2efb1596bc73Michal Zidek return ret;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek}
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Getpwuid-wrapper======================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
7ff5374d0103f8e2e03ef15790838b85918153aeLukas Slebodnikstatic int get_pw_uid(struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher uid_t uid)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct passwd *pwd;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *buffer;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher size_t buflen;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher bool del_user = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *name;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Searching user by uid (%"SPRIuid")\n", uid);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek tmpctx = talloc_new(NULL);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher pwd = talloc_zero(tmpctx, struct passwd);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!pwd) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buflen = DEFAULT_BUFSIZE;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buffer = talloc_size(tmpctx, buflen);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher status = ctx->ops.getpwuid_r(uid, pwd, buffer, buflen, &ret);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = handle_getpw_result(status, pwd, dom, &del_user);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getpwuid failed [%d]: %s\n", ret, strerror(ret));
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (del_user) {
428f137041034362a1cc6b64d68011a1d3f67cd7Lukas Slebodnik ret = delete_user(dom, NULL, uid);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek name = sss_create_internal_fqname(tmpctx, pwd->pw_name, dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "failed to qualify name '%s'\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek pwd->pw_name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
2537fe318a3866780abca100cf6eb7c258f9d02bFabiano Fidêncio ret = save_user(dom, pwd, name, NULL);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherdone:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher talloc_zfree(tmpctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "proxy -> getpwuid_r failed for '%"SPRIuid"' <%d>: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov uid, ret, strerror(ret));
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Getpwent-wrapper======================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherstatic int enum_users(TALLOC_CTX *mem_ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher bool in_transaction = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct passwd *pwd;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher size_t buflen;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *buffer;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *newbuf;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek errno_t sret;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos bool again;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *name;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Enumerating users\n");
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher tmpctx = talloc_new(mem_ctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher pwd = talloc_zero(tmpctx, struct passwd);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!pwd) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buflen = DEFAULT_BUFSIZE;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buffer = talloc_size(tmpctx, buflen);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = sysdb_transaction_start(sysdb);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher in_transaction = true;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher status = ctx->ops.setpwent();
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (status != NSS_STATUS_SUCCESS) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = EIO;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos do {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = false;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* always zero out the pwd structure */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos memset(pwd, 0, sizeof(struct passwd));
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* get entry */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos status = ctx->ops.getpwent_r(pwd, buffer, buflen, &ret);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos switch (status) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_TRYAGAIN:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* buffer too small ? */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (buflen < MAX_BUF_SIZE) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos buflen *= 2;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (buflen > MAX_BUF_SIZE) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos buflen = MAX_BUF_SIZE;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos newbuf = talloc_realloc_size(tmpctx, buffer, buflen);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (!newbuf) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = ENOMEM;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos goto done;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos buffer = newbuf;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = true;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_NOTFOUND:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* we are done here */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Enumeration completed.\n");
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = sysdb_transaction_commit(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos in_transaction = false;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_SUCCESS:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
a4bf85ccc902490c3b75b44532010fbb32169801Lukas Slebodnik DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User found (%s, %"SPRIuid", %"SPRIgid")\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov pwd->pw_name, pwd->pw_uid, pwd->pw_gid);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* uid=0 or gid=0 are invalid values */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* also check that the id is in the valid range for this domain
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (OUT_OF_ID_RANGE(pwd->pw_uid, dom->id_min, dom->id_max) ||
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos OUT_OF_ID_RANGE(pwd->pw_gid, dom->id_min, dom->id_max)) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "User [%s] filtered out! (id out"
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov " of range)\n", pwd->pw_name);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = true;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek name = sss_create_internal_fqname(tmpctx, pwd->pw_name, dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek "failed to create internal name '%s'\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek pwd->pw_name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
2537fe318a3866780abca100cf6eb7c258f9d02bFabiano Fidêncio ret = save_user(dom, pwd, name, NULL);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (ret) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* Do not fail completely on errors.
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos * Just report the failure to save and go on */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to store user %s."
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov " Ignoring.\n", pwd->pw_name);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = true;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_UNAVAIL:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* "remote" backend unavailable. Enter offline mode */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = ENXIO;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos default:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = EIO;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "proxy -> getpwent_r failed (%d)[%s]"
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "\n", ret, strerror(ret));
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos } while (again);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherdone:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher talloc_zfree(tmpctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (in_transaction) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek sret = sysdb_transaction_cancel(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ctx->ops.endpwent();
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek/* =Save-group-utilities=================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher#define DEBUG_GR_MEM(level, grp) \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher do { \
5c233380e1ebf641f6106a34d7b94f9e9a606589Nikolai Kondrashov if (DEBUG_IS_SET(level)) { \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!grp->gr_mem || !grp->gr_mem[0]) { \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(level, "Group %s has no members!\n", \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov grp->gr_name); \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher } else { \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int i = 0; \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher while (grp->gr_mem[i]) { \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher /* count */ \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher i++; \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher } \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(level, "Group %s has %d members!\n", \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov grp->gr_name, i); \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher } \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher } \
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher } while(0)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagherstatic errno_t proxy_process_missing_users(struct sysdb_ctx *sysdb,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce struct sss_domain_info *domain,
8c8cbddeabe585377a5fb3d5df09cc9a236b77ddJan Zeleny struct sysdb_attrs *group_attrs,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek const char *const*fq_gr_mem,
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher time_t now);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozekstatic int save_group(struct sysdb_ctx *sysdb, struct sss_domain_info *dom,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek struct group *grp,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek const char *real_name, /* already qualified */
221d70ae3c5b7bc7384f57ffd3f88f89a3e6ae6aFabiano Fidêncio const char *alias) /* already qualified */
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek{
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher errno_t ret, sret;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek struct sysdb_attrs *attrs = NULL;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek TALLOC_CTX *tmp_ctx;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher time_t now = time(NULL);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher bool in_transaction = false;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char **fq_gr_mem;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek tmp_ctx = talloc_new(NULL);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek if (!tmp_ctx) {
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek return ENOMEM;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG_GR_MEM(SSSDBG_TRACE_LIBS, grp);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher ret = sysdb_transaction_start(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher in_transaction = true;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek if (grp->gr_mem && grp->gr_mem[0]) {
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek attrs = sysdb_new_attrs(tmp_ctx);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek if (!attrs) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Allocation error ?!\n");
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek ret = ENOMEM;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek goto done;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek fq_gr_mem = sss_create_internal_fqname_list(
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek tmp_ctx,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek (const char *const*) grp->gr_mem,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (fq_gr_mem == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = ENOMEM;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek ret = sysdb_attrs_users_from_str_list(
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek attrs, SYSDB_MEMBER, dom->name,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek (const char *const *) fq_gr_mem);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not add group members\n");
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek goto done;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
8c8cbddeabe585377a5fb3d5df09cc9a236b77ddJan Zeleny /* Create ghost users */
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = proxy_process_missing_users(sysdb, dom, attrs,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek (const char *const*) fq_gr_mem, now);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not add missing members\n");
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher goto done;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio ret = prepare_attrs_for_saving_ops(tmp_ctx, dom->case_sensitive,
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio real_name, alias, &attrs);
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio if (ret != EOK) {
69e8b7fcb9e3dc814a9ffc2a97fa656521cc4505Fabiano Fidêncio goto done;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_store_group(dom,
51773686d354b82081830444c048706d83d43d65Jakub Hrozek real_name,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek grp->gr_gid,
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek attrs,
221d70ae3c5b7bc7384f57ffd3f88f89a3e6ae6aFabiano Fidêncio dom->group_timeout,
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher now);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not add group to cache\n");
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek goto done;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek }
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher ret = sysdb_transaction_commit(sysdb);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (ret != EOK) {
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not commit transaction: [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov strerror(ret));
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher goto done;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher in_transaction = false;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagherdone:
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (in_transaction) {
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher sret = sysdb_transaction_cancel(sysdb);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not cancel transaction\n");
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher talloc_free(tmp_ctx);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher return ret;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher}
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagherstatic errno_t proxy_process_missing_users(struct sysdb_ctx *sysdb,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce struct sss_domain_info *domain,
8c8cbddeabe585377a5fb3d5df09cc9a236b77ddJan Zeleny struct sysdb_attrs *group_attrs,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek const char *const*fq_gr_mem,
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher time_t now)
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher{
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher errno_t ret;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher size_t i;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher TALLOC_CTX *tmp_ctx = NULL;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher struct ldb_message *msg;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (!sysdb || !fq_gr_mem) return EINVAL;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher tmp_ctx = talloc_new(NULL);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (!tmp_ctx) return ENOMEM;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek for (i = 0; fq_gr_mem[i]; i++) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sysdb_search_user_by_name(tmp_ctx, domain, fq_gr_mem[i],
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek NULL, &msg);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (ret == EOK) {
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher /* Member already exists in the cache */
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher DEBUG(SSSDBG_TRACE_INTERNAL,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek "Member [%s] already cached\n", fq_gr_mem[i]);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher /* clean up */
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher talloc_zfree(msg);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher continue;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher } else if (ret == ENOENT) {
8c8cbddeabe585377a5fb3d5df09cc9a236b77ddJan Zeleny /* No entry for this user. Create a ghost user */
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Member [%s] not cached, creating ghost user entry\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek fq_gr_mem[i]);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sysdb_attrs_add_string(group_attrs, SYSDB_GHOST, fq_gr_mem[i]);
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher if (ret != EOK) {
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot store ghost user entry: [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher goto done;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher } else {
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher /* Unexpected error */
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Error searching cache for user [%s]: [%s]\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek fq_gr_mem[i], strerror(ret));
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher goto done;
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher }
b6a8bdebb40a63d2adc50c574fee88229d1e8f3dStephen Gallagher
c9041cb7addc1a49e0771246d17de101662fbcbcJakub Hrozek ret = EOK;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozekdone:
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek talloc_free(tmp_ctx);
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek return ret;
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek}
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek
4e9631a9f1ae87317eef53145622099c46196b56Jakub Hrozek/* =Getgrnam-wrapper======================================================*/
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekstatic char *
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekgrow_group_buffer(TALLOC_CTX *mem_ctx,
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek char **buffer, size_t *buflen)
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek{
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek char *newbuf;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (*buflen == 0) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *buflen = DEFAULT_BUFSIZE;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (*buflen < MAX_BUF_SIZE) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *buflen *= 2;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (*buflen > MAX_BUF_SIZE) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *buflen = MAX_BUF_SIZE;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek newbuf = talloc_realloc_size(mem_ctx, *buffer, *buflen);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (!newbuf) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return NULL;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *buffer = newbuf;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return *buffer;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek}
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekstatic errno_t
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekhandle_getgr_result(enum nss_status status, struct group *grp,
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek struct sss_domain_info *dom,
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek bool *delete_group)
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek{
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek switch (status) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek case NSS_STATUS_TRYAGAIN:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Buffer too small\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return EAGAIN;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek case NSS_STATUS_NOTFOUND:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Group not found.\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *delete_group = true;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek break;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek case NSS_STATUS_SUCCESS:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "Group found: (%s, %"SPRIgid")\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov grp->gr_name, grp->gr_gid);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* gid=0 is an invalid value */
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* also check that the id is in the valid range for this domain */
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (OUT_OF_ID_RANGE(grp->gr_gid, dom->id_min, dom->id_max)) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group filtered out! (id out of range)\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek *delete_group = true;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek break;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek break;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek case NSS_STATUS_UNAVAIL:
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Remote back end is not available. Entering offline mode\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return ENXIO;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek default:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unknown return code %d\n", status);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return EIO;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek return EOK;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek}
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
7ff5374d0103f8e2e03ef15790838b85918153aeLukas Slebodnikstatic int get_gr_name(struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek const char *i_name)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct group *grp;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek char *buffer = 0;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek size_t buflen = 0;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher bool delete_group = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek gid_t gid;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek struct ldb_result *cached_grp = NULL;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek const char *real_name = NULL;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *shortname_or_alias;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_FUNC_DATA, "Searching group by name (%s)\n", i_name);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek tmpctx = talloc_new(NULL);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sss_parse_internal_fqname(tmpctx, i_name, &shortname_or_alias, NULL);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (ret != EOK) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher grp = talloc(tmpctx, struct group);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!grp) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "proxy -> getgrnam_r failed for '%s': [%d] %s\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek i_name, ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek do {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* always zero out the grp structure */
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek memset(grp, 0, sizeof(struct group));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek buffer = grow_group_buffer(tmpctx, &buffer, &buflen);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek status = ctx->ops.getgrnam_r(shortname_or_alias, grp, buffer,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek buflen, &ret);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = handle_getgr_result(status, grp, dom, &delete_group);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek } while (ret == EAGAIN);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret != EOK) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getgrnam failed [%d]: %s\n", ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (delete_group) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek "Group %s does not exist (or is invalid) on remote server,"
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek " deleting!\n", i_name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sysdb_delete_group(dom, i_name, 0);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (ret == ENOENT) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = EOK;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek gid = grp->gr_gid;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* Canonicalize the group name in case it was actually an alias */
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ctx->fast_alias == true) {
b3292840ebaa747a9fd596ff47cc5d18198361d0Michal Zidek ret = sysdb_getgrgid(tmpctx, dom, gid, &cached_grp);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret != EOK) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek /* Non-fatal, attempt to canonicalize online */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Request to cache failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret == EOK && cached_grp->count == 1) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek real_name = ldb_msg_find_attr_as_string(cached_grp->msgs[0],
51773686d354b82081830444c048706d83d43d65Jakub Hrozek SYSDB_NAME, NULL);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (!real_name) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Cached group has no name?\n");
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (real_name == NULL) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek talloc_zfree(buffer);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek buflen = 0;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek do {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek memset(grp, 0, sizeof(struct group));
51773686d354b82081830444c048706d83d43d65Jakub Hrozek buffer = grow_group_buffer(tmpctx, &buffer, &buflen);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (!buffer) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek ret = ENOMEM;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek goto done;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek status = ctx->ops.getgrgid_r(gid, grp, buffer, buflen, &ret);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek ret = handle_getgr_result(status, grp, dom, &delete_group);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek } while (ret == EAGAIN);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret != EOK) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getgrgid failed [%d]: %s\n", ret, strerror(ret));
51773686d354b82081830444c048706d83d43d65Jakub Hrozek goto done;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek real_name = sss_create_internal_fqname(tmpctx, grp->gr_name, dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (real_name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to create fqdn '%s'\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek grp->gr_name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = ENOMEM;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (delete_group) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group %s does not exist (or is invalid) on remote server,"
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek " deleting!\n", i_name);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sysdb_delete_group(dom, i_name, gid);
2bc09619e5c8f8c02bcd169ade1878ef28aedb4cOndrej Kos if (ret == ENOENT) {
2bc09619e5c8f8c02bcd169ade1878ef28aedb4cOndrej Kos ret = EOK;
2bc09619e5c8f8c02bcd169ade1878ef28aedb4cOndrej Kos }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
221d70ae3c5b7bc7384f57ffd3f88f89a3e6ae6aFabiano Fidêncio ret = save_group(sysdb, dom, grp, real_name, i_name);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot save group [%d]: %s\n", ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherdone:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher talloc_zfree(tmpctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "proxy -> getgrnam_r failed for '%s' <%d>: %s\n",
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek i_name, ret, strerror(ret));
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Getgrgid-wrapper======================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherstatic int get_gr_gid(TALLOC_CTX *mem_ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina gid_t gid,
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina time_t now)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct group *grp;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek char *buffer = NULL;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek size_t buflen = 0;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher bool delete_group = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *name;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Searching group by gid (%"SPRIgid")\n", gid);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher tmpctx = talloc_new(mem_ctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher grp = talloc(tmpctx, struct group);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!grp) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek do {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* always zero out the grp structure */
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek memset(grp, 0, sizeof(struct group));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek buffer = grow_group_buffer(tmpctx, &buffer, &buflen);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek status = ctx->ops.getgrgid_r(gid, grp, buffer, buflen, &ret);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = handle_getgr_result(status, grp, dom, &delete_group);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek } while (ret == EAGAIN);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce if (ret != EOK) {
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getgrgid failed [%d]: %s\n", ret, strerror(ret));
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce goto done;
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce }
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (delete_group) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group %"SPRIgid" does not exist (or is invalid) on remote "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "server, deleting!\n", gid);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_delete_group(dom, NULL, gid);
2bc09619e5c8f8c02bcd169ade1878ef28aedb4cOndrej Kos if (ret == ENOENT) {
2bc09619e5c8f8c02bcd169ade1878ef28aedb4cOndrej Kos ret = EOK;
2bc09619e5c8f8c02bcd169ade1878ef28aedb4cOndrej Kos }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek name = sss_create_internal_fqname(tmpctx, grp->gr_name, dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = ENOMEM;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
221d70ae3c5b7bc7384f57ffd3f88f89a3e6ae6aFabiano Fidêncio ret = save_group(sysdb, dom, grp, name, NULL);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot save user [%d]: %s\n", ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherdone:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher talloc_zfree(tmpctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "proxy -> getgrgid_r failed for '%"SPRIgid"' <%d>: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov gid, ret, strerror(ret));
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Getgrent-wrapper======================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherstatic int enum_groups(TALLOC_CTX *mem_ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher bool in_transaction = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct group *grp;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher size_t buflen;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *buffer;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *newbuf;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek errno_t sret;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos bool again;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *name;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Enumerating groups\n");
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher tmpctx = talloc_new(mem_ctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher grp = talloc(tmpctx, struct group);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!grp) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buflen = DEFAULT_BUFSIZE;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buffer = talloc_size(tmpctx, buflen);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = sysdb_transaction_start(sysdb);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher in_transaction = true;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher status = ctx->ops.setgrent();
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (status != NSS_STATUS_SUCCESS) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = EIO;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher goto done;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos do {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* always zero out the grp structure */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos memset(grp, 0, sizeof(struct group));
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* get entry */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos status = ctx->ops.getgrent_r(grp, buffer, buflen, &ret);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos switch (status) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_TRYAGAIN:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* buffer too small ? */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (buflen < MAX_BUF_SIZE) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos buflen *= 2;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (buflen > MAX_BUF_SIZE) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos buflen = MAX_BUF_SIZE;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos newbuf = talloc_realloc_size(tmpctx, buffer, buflen);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (!newbuf) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = ENOMEM;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos goto done;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos buffer = newbuf;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = true;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_NOTFOUND:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* we are done here */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Enumeration completed.\n");
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = sysdb_transaction_commit(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek goto done;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos in_transaction = false;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_SUCCESS:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Group found (%s, %"SPRIgid")\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov grp->gr_name, grp->gr_gid);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* gid=0 is an invalid value */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* also check that the id is in the valid range for this domain
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (OUT_OF_ID_RANGE(grp->gr_gid, dom->id_min, dom->id_max)) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Group [%s] filtered out! (id"
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "out of range)\n", grp->gr_name);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = true;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek name = sss_create_internal_fqname(tmpctx, grp->gr_name,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to create internal fqname "
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek "Ignoring\n");
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = ENOMEM;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
221d70ae3c5b7bc7384f57ffd3f88f89a3e6ae6aFabiano Fidêncio ret = save_group(sysdb, dom, grp, name, NULL);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (ret) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* Do not fail completely on errors.
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos * Just report the failure to save and go on */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to store group."
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Ignoring\n");
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos again = true;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos case NSS_STATUS_UNAVAIL:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* "remote" backend unavailable. Enter offline mode */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = ENXIO;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos default:
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos ret = EIO;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "proxy -> getgrent_r failed (%d)[%s]"
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "\n", ret, strerror(ret));
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos } while (again);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherdone:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher talloc_zfree(tmpctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (in_transaction) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek sret = sysdb_transaction_cancel(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ctx->ops.endgrent();
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Initgroups-wrapper====================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherstatic int get_initgr_groups_process(TALLOC_CTX *memctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct passwd *pwd);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherstatic int get_initgr(TALLOC_CTX *mem_ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek const char *i_name)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher TALLOC_CTX *tmpctx;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher bool in_transaction = false;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct passwd *pwd;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher char *buffer;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher size_t buflen;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek errno_t sret;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek bool del_user;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek uid_t uid;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek struct ldb_result *cached_pwd = NULL;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek const char *real_name = NULL;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek char *shortname_or_alias;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher tmpctx = talloc_new(mem_ctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!tmpctx) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = sss_parse_internal_fqname(tmpctx, i_name, &shortname_or_alias, NULL);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (ret != EOK) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher pwd = talloc_zero(tmpctx, struct passwd);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!pwd) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buflen = DEFAULT_BUFSIZE;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher buffer = talloc_size(tmpctx, buflen);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!buffer) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = ENOMEM;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher ret = sysdb_transaction_start(sysdb);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher in_transaction = true;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher /* FIXME: should we move this call outside the transaction to keep the
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher * transaction as short as possible ? */
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek status = ctx->ops.getpwnam_r(shortname_or_alias, pwd,
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek buffer, buflen, &ret);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = handle_getpw_result(status, pwd, dom, &del_user);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getpwnam failed [%d]: %s\n", ret, strerror(ret));
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (del_user) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = delete_user(dom, i_name, 0);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not delete user\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek uid = pwd->pw_uid;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek memset(buffer, 0, buflen);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek /* Canonicalize the username in case it was actually an alias */
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ctx->fast_alias == true) {
b3292840ebaa747a9fd596ff47cc5d18198361d0Michal Zidek ret = sysdb_getpwuid(tmpctx, dom, uid, &cached_pwd);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret != EOK) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek /* Non-fatal, attempt to canonicalize online */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Request to cache failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret == EOK && cached_pwd->count == 1) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek real_name = ldb_msg_find_attr_as_string(cached_pwd->msgs[0],
51773686d354b82081830444c048706d83d43d65Jakub Hrozek SYSDB_NAME, NULL);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (!real_name) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Cached user has no name?\n");
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (real_name == NULL) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek memset(buffer, 0, buflen);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
51773686d354b82081830444c048706d83d43d65Jakub Hrozek status = ctx->ops.getpwuid_r(uid, pwd, buffer, buflen, &ret);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek ret = handle_getpw_result(status, pwd, dom, &del_user);
51773686d354b82081830444c048706d83d43d65Jakub Hrozek if (ret) {
51773686d354b82081830444c048706d83d43d65Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "getpwuid failed [%d]: %s\n", ret, strerror(ret));
51773686d354b82081830444c048706d83d43d65Jakub Hrozek goto done;
51773686d354b82081830444c048706d83d43d65Jakub Hrozek }
51773686d354b82081830444c048706d83d43d65Jakub Hrozek
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek real_name = sss_create_internal_fqname(tmpctx, pwd->pw_name, dom->name);
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek if (real_name == NULL) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = ENOMEM;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek goto done;
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (del_user) {
526d4d5e5a916cf30a043836cba14eab529cb7b1Jakub Hrozek ret = delete_user(dom, i_name, uid);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not delete user\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto done;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2537fe318a3866780abca100cf6eb7c258f9d02bFabiano Fidêncio ret = save_user(dom, pwd, real_name, i_name);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not save user\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = get_initgr_groups_process(tmpctx, ctx, sysdb, dom, pwd);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not process initgroups\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherdone:
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek ret = sysdb_transaction_commit(sysdb);
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to commit transaction\n");
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek goto fail;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek }
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek in_transaction = false;
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozek
28d1ff294f7d612f6d37c82ed426b8bf5c34bfafJakub Hrozekfail:
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher talloc_zfree(tmpctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (in_transaction) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek sret = sysdb_transaction_cancel(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagherstatic int get_initgr_groups_process(TALLOC_CTX *memctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct proxy_id_ctx *ctx,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sss_domain_info *dom,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct passwd *pwd)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher enum nss_status status;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher long int limit;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher long int size;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher long int num;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher long int num_gids;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher gid_t *gids;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher int i;
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina time_t now;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher num_gids = 0;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher limit = 4096;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher num = 4096;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher size = num*sizeof(gid_t);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher gids = talloc_size(memctx, size);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (!gids) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ENOMEM;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce /* nss modules may skip the primary group when we pass it in so always add
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce * it in advance */
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce gids[0] = pwd->pw_gid;
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce num_gids++;
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher /* FIXME: should we move this call outside the transaction to keep the
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher * transaction as short as possible ? */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos do {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos status = ctx->ops.initgroups_dyn(pwd->pw_name, pwd->pw_gid, &num_gids,
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos &num, &gids, limit, &ret);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (status == NSS_STATUS_TRYAGAIN) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos /* buffer too small ? */
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (size < MAX_BUF_SIZE) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos num *= 2;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos size = num*sizeof(gid_t);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (size > MAX_BUF_SIZE) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos size = MAX_BUF_SIZE;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos num = size/sizeof(gid_t);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos limit = num;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos gids = talloc_realloc_size(memctx, gids, size);
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos if (!gids) {
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos return ENOMEM;
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos } while(status == NSS_STATUS_TRYAGAIN);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
499718cb04a534ba76ee9dfb055c2bfc96fdeeb3Ondrej Kos switch (status) {
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce case NSS_STATUS_NOTFOUND:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "The initgroups call returned 'NOTFOUND'. "
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce "Assume the user is only member of its "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "primary group (%"SPRIgid")\n", pwd->pw_gid);
66d1f565dfb39325ab7daa264b5795b1f348756eSimo Sorce /* fall through */
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case NSS_STATUS_SUCCESS:
18e24f20a4aef66a4899367a0775a98ab2acd18ePavel Reichl DEBUG(SSSDBG_CONF_SETTINGS, "User [%s] appears to be member of %lu "
18e24f20a4aef66a4899367a0775a98ab2acd18ePavel Reichl "groups\n", pwd->pw_name, num_gids);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina now = time(NULL);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher for (i = 0; i < num_gids; i++) {
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina ret = get_gr_gid(memctx, ctx, sysdb, dom, gids[i], now);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
4a305e734e2fb34905e62eecb4282bb87ebc5f24Sumit Bose ret = EOK;
4a305e734e2fb34905e62eecb4282bb87ebc5f24Sumit Bose
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher default:
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "proxy -> initgroups_dyn failed (%d)[%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
4a305e734e2fb34905e62eecb4282bb87ebc5f24Sumit Bose ret = EIO;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher return ret;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher/* =Proxy_Id-Functions====================================================*/
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic struct dp_reply_std
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaproxy_account_info(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_id_ctx *ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct be_ctx *be_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sss_domain_info *domain)
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher struct sysdb_ctx *sysdb;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher uid_t uid;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher gid_t gid;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
d1571f8c173ca9172fa295e6aac48b8c0c367950Sumit Bose char *endptr;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sysdb = domain->sysdb;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* For now we support only core attrs. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data->attr_type != BE_ATTR_CORE) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL, "Invalid attr type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* Proxy provider does not support security ID lookups. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data->filter_type == BE_FILTER_SECID) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ENOSYS,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Security lookups are not supported");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
206329d3901738036352f2ac1e8d7804f728861dSumit Bose }
206329d3901738036352f2ac1e8d7804f728861dSumit Bose
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina switch (data->entry_type & BE_REQ_TYPE_MASK) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_REQ_USER: /* user */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina switch (data->filter_type) {
d1571f8c173ca9172fa295e6aac48b8c0c367950Sumit Bose case BE_FILTER_ENUM:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = enum_users(mem_ctx, ctx, sysdb, domain);
d1571f8c173ca9172fa295e6aac48b8c0c367950Sumit Bose break;
d1571f8c173ca9172fa295e6aac48b8c0c367950Sumit Bose
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_FILTER_NAME:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = get_pw_name(ctx, domain, data->filter_value);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_FILTER_IDNUM:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uid = (uid_t) strtouint32(data->filter_value, &endptr, 10);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (errno || *endptr || (data->filter_value == endptr)) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid attr type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
7ff5374d0103f8e2e03ef15790838b85918153aeLukas Slebodnik ret = get_pw_uid(ctx, domain, uid);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher default:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid filter type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_REQ_GROUP: /* group */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina switch (data->filter_type) {
d1571f8c173ca9172fa295e6aac48b8c0c367950Sumit Bose case BE_FILTER_ENUM:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = enum_groups(mem_ctx, ctx, sysdb, domain);
d1571f8c173ca9172fa295e6aac48b8c0c367950Sumit Bose break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_FILTER_NAME:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = get_gr_name(ctx, sysdb, domain, data->filter_value);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_FILTER_IDNUM:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina gid = (gid_t) strtouint32(data->filter_value, &endptr, 10);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (errno || *endptr || (data->filter_value == endptr)) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid attr type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = get_gr_gid(mem_ctx, ctx, sysdb, domain, gid, 0);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher default:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid filter type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher case BE_REQ_INITGROUPS: /* init groups for user */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data->filter_type != BE_FILTER_NAME) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid filter type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ctx->ops.initgroups_dyn == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Initgroups call not supported");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = get_initgr(mem_ctx, ctx, sysdb, domain, data->filter_value);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher break;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose case BE_REQ_NETGROUP:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data->filter_type != BE_FILTER_NAME) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid filter type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose }
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose if (ctx->ops.setnetgrent == NULL || ctx->ops.getnetgrent_r == NULL ||
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose ctx->ops.endnetgrent == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Netgroups are not supported");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose }
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = get_netgroup(ctx, domain, data->filter_value);
04feeade1f6259368a6b23c6b3ecbad261161659Sumit Bose break;
d7dc57bcc2468bee756bcd568daee0644e5b888dSumit Bose
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher case BE_REQ_SERVICES:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina switch (data->filter_type) {
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher case BE_FILTER_NAME:
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher if (ctx->ops.getservbyname_r == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Services are not supported");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher }
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = get_serv_byname(ctx, domain,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_value,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->extra_value);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher break;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher case BE_FILTER_IDNUM:
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher if (ctx->ops.getservbyport_r == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Services are not supported");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher }
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = get_serv_byport(ctx, domain,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_value,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->extra_value);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher break;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher case BE_FILTER_ENUM:
627d83dff183219826489949cb55ef71945e94abStephen Gallagher if (!ctx->ops.setservent
627d83dff183219826489949cb55ef71945e94abStephen Gallagher || !ctx->ops.getservent_r
627d83dff183219826489949cb55ef71945e94abStephen Gallagher || !ctx->ops.endservent) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Services are not supported");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
627d83dff183219826489949cb55ef71945e94abStephen Gallagher }
627d83dff183219826489949cb55ef71945e94abStephen Gallagher ret = enum_services(ctx, sysdb, domain);
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher break;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher default:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid filter type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher }
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher break;
aec5785126354bd8b192f63fe04ea08dae9c0705Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher default: /*fail*/
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Invalid filter type");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret) {
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher if (ret == ENXIO) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "proxy returned UNAVAIL error, going offline!\n");
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce be_mark_offline(be_ctx);
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_FATAL, ret, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&reply, DP_ERR_OK, EOK, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct proxy_account_info_handler_state {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina};
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct tevent_req *
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaproxy_account_info_handler_send(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_id_ctx *id_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_req_params *params)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_account_info_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_create(mem_ctx, &state,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (req == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return NULL;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state->reply = proxy_account_info(state, id_ctx, data, params->be_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina params->be_ctx->domain);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_post(req, params->ev);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t proxy_account_info_handler_recv(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std *data)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_account_info_handler_state *state = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct proxy_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina *data = state->reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return EOK;
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher}