sss_sync_ops.c revision e5e32021c23f3726d68ee756e8e3de48b3214063
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder/*
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder Authors:
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder Jakub Hrozek <jhrozek@redhat.com>
b03274844ecd270f9e9331f51cc4236a33e2e671Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder Copyright (C) 2009 Red Hat
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder This program is free software; you can redistribute it and/or modify
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder it under the terms of the GNU General Public License as published by
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder the Free Software Foundation; either version 3 of the License, or
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski (at your option) any later version.
679d3f541f7a9ede4079e045f7758873bb901872Till Mossakowski
679d3f541f7a9ede4079e045f7758873bb901872Till Mossakowski This program is distributed in the hope that it will be useful,
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski but WITHOUT ANY WARRANTY; without even the implied warranty of
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder GNU General Public License for more details.
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder You should have received a copy of the GNU General Public License
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder*/
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder#include <tevent.h>
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder#include <talloc.h>
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder#include <sys/types.h>
74b841a4b332085d5fd79975a13313c2681ae595Christian Maeder
74b841a4b332085d5fd79975a13313c2681ae595Christian Maeder#include "util/util.h"
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder#include "db/sysdb.h"
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder#include "tools/sss_sync_ops.h"
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
43b4c41fbb07705c9df321221ab9cb9832460407Christian Maeder/* Default settings for user attributes */
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder#define DFL_SHELL_VAL "/bin/bash"
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder#define DFL_BASEDIR_VAL "/home"
7bf4436b6f9987b070033a323757b206c898c1beChristian Maeder#define DFL_CREATE_HOMEDIR "TRUE"
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski#define DFL_REMOVE_HOMEDIR "TRUE"
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder#define DFL_UMASK 077
410ff490af511ffa09b52e4de631d36a154b9730Christian Maeder#define DFL_SKEL_DIR "/etc/skel"
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder#define DFL_MAIL_DIR "/var/spool/mail"
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder#define VAR_CHECK(var, val, attr, msg) do { \
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder if (var != (val)) { \
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian Maeder DEBUG(1, (msg" attribute: %s", attr)); \
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return val; \
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder } \
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder} while(0)
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder#define SYNC_LOOP(ops, retval) do { \
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder while (!ops->done) { \
410ff490af511ffa09b52e4de631d36a154b9730Christian Maeder tevent_loop_once(ev); \
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder } \
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder retval = ops->error; \
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder} while(0)
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstruct sync_op_res {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct ops_ctx *data;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int error;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder bool done;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder};
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder/*
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder * Generic modify groups member
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstatic int mod_groups_member(TALLOC_CTX *mem_ctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct sysdb_ctx *sysdb,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct sss_domain_info *domain,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder char **grouplist,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct ldb_dn *member_dn,
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder int optype)
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder{
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder TALLOC_CTX *tmpctx;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder struct ldb_dn *parent_dn;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder int ret;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder int i;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder tmpctx = talloc_new(NULL);
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder if (!tmpctx) {
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder return ENOMEM;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder/* FIXME: add transaction around loop */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder for (i = 0; grouplist[i]; i++) {
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder parent_dn = sysdb_group_dn(sysdb, tmpctx,
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder domain->name,
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder grouplist[i]);
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder if (!parent_dn) {
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder ret = ENOMEM;
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder goto done;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder ret = sysdb_mod_group_member(tmpctx, sysdb,
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder member_dn, parent_dn, optype);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder if (ret) {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder goto done;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder }
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder ret = EOK;
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maederdone:
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder talloc_zfree(tmpctx);
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder return ret;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder}
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder#define add_to_groups(memctx, sysdb, data, member_dn) \
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder mod_groups_member(memctx, sysdb, data->domain, \
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder data->addgroups, member_dn, LDB_FLAG_MOD_ADD)
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder#define remove_from_groups(memctx, sysdb, data, member_dn) \
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder mod_groups_member(memctx, sysdb, data->domain, \
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder data->rmgroups, member_dn, LDB_FLAG_MOD_DELETE)
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder/*
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder * Modify a user
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder */
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maederstruct user_mod_state {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder struct tevent_context *ev;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder struct sysdb_ctx *sysdb;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder struct sysdb_attrs *attrs;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder struct ldb_dn *member_dn;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder struct ops_ctx *data;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder};
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maederstatic int usermod_build_attrs(TALLOC_CTX *mem_ctx,
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder const char *gecos,
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder const char *home,
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder const char *shell,
97f7ac06b3cbf4fc22c0a9eef523b68ee34fc164Christian Maeder uid_t uid,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder gid_t gid,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int lock,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct sysdb_attrs **_attrs)
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder{
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int ret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct sysdb_attrs *attrs;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder attrs = sysdb_new_attrs(mem_ctx);
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder if (attrs == NULL) {
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder return ENOMEM;
792df0347edab377785d98c63e2be8e2ce0a8bdeChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (shell) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = sysdb_attrs_add_string(attrs,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder SYSDB_SHELL,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder shell);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder VAR_CHECK(ret, EOK, SYSDB_SHELL,
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder "Could not add attribute to changeset\n");
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder }
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder if (home) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = sysdb_attrs_add_string(attrs,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder SYSDB_HOMEDIR,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder home);
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder VAR_CHECK(ret, EOK, SYSDB_HOMEDIR,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder "Could not add attribute to changeset\n");
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder }
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder if (gecos) {
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder ret = sysdb_attrs_add_string(attrs,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder SYSDB_GECOS,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder gecos);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder VAR_CHECK(ret, EOK, SYSDB_GECOS,
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder "Could not add attribute to changeset\n");
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder if (uid) {
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder ret = sysdb_attrs_add_long(attrs,
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder SYSDB_UIDNUM,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder uid);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder VAR_CHECK(ret, EOK, SYSDB_UIDNUM,
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder "Could not add attribute to changeset\n");
1c8c2b04b40b5c054da07b8d059e5ef29d4dbc32Christian Maeder }
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder if (gid) {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = sysdb_attrs_add_long(attrs,
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski SYSDB_GIDNUM,
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder gid);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder VAR_CHECK(ret, EOK, SYSDB_GIDNUM,
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowski "Could not add attribute to changeset\n");
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder if (lock == DO_LOCK) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sysdb_attrs_add_string(attrs,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder SYSDB_DISABLED,
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder "true");
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder VAR_CHECK(ret, EOK, SYSDB_DISABLED,
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski "Could not add attribute to changeset\n");
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder }
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder if (lock == DO_UNLOCK) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* PAM code checks for 'false' value in SYSDB_DISABLED attribute */
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = sysdb_attrs_add_string(attrs,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder SYSDB_DISABLED,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "false");
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder VAR_CHECK(ret, EOK, SYSDB_DISABLED,
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder "Could not add attribute to changeset\n");
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder *_attrs = attrs;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder return EOK;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder}
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder/*
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder * Public interface for modifying users
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski */
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maederint usermod(TALLOC_CTX *mem_ctx,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski struct sysdb_ctx *sysdb,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct ops_ctx *data)
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder{
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct sysdb_attrs *attrs;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder struct ldb_dn *member_dn;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski int ret;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder if (data->addgroups || data->rmgroups) {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder member_dn = sysdb_user_dn(sysdb, mem_ctx,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder data->domain->name, data->name);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (!member_dn) {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder return ENOMEM;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = usermod_build_attrs(mem_ctx,
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder data->gecos,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder data->home,
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder data->shell,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder data->uid,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder data->gid,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder data->lock,
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder &attrs);
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski if (ret != EOK) {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder return ret;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (attrs->num != 0) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = sysdb_set_user_attr(mem_ctx, sysdb,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski data->domain, data->name,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski attrs, SYSDB_MOD_REP);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder if (ret) {
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return ret;
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder }
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder if (data->rmgroups != NULL) {
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder ret = remove_from_groups(mem_ctx, sysdb, data, member_dn);
21dae7237ac384abdb94a81e00b3f099873ec623Till Mossakowski if (ret) {
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder return ret;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder if (data->addgroups != NULL) {
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder if (ret) {
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder return ret;
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder }
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder }
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_PASSWD);
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return EOK;
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski}
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder
e24d81c69aecd41abb2f4969519c9e7126b1d687Christian Maeder/*
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder * Public interface for modifying groups
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder */
6157bf81d295795067c177aa870fedff83cbe750Christian Maederint groupmod(TALLOC_CTX *mem_ctx,
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder struct sysdb_ctx *sysdb,
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder struct ops_ctx *data)
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder{
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder struct sysdb_attrs *attrs;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder struct ldb_dn *member_dn;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder int ret;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder if (data->addgroups || data->rmgroups) {
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder member_dn = sysdb_group_dn(sysdb, mem_ctx,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski data->domain->name, data->name);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder if (!member_dn) {
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return ENOMEM;
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder if (data->gid != 0) {
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder attrs = sysdb_new_attrs(mem_ctx);
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder if (!attrs) {
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder return ENOMEM;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, data->gid);
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski if (ret) {
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return ret;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder ret = sysdb_set_group_attr(mem_ctx, sysdb,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder data->domain, data->name,
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski attrs, SYSDB_MOD_REP);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder if (ret) {
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski return ret;
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder if (data->rmgroups != NULL) {
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = remove_from_groups(mem_ctx, sysdb, data, member_dn);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder if (ret) {
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder return ret;
a980a2f16eda9aad70f1f53f9df713595f57cb78Jian Chun Wang }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder if (data->addgroups != NULL) {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (ret) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder return ret;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder }
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder }
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder return EOK;
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder}
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maederint userdel_defaults(TALLOC_CTX *mem_ctx,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski struct confdb_ctx *confdb,
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder struct ops_ctx *data,
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder int remove_home)
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder{
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder int ret;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder char *conf_path;
2cafc2361fcaccf6b82d81f6a94f59e42af725c7Christian Maeder bool dfl_remove_home;
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder conf_path = talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL, data->domain->name);
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder if (!conf_path) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder return ENOMEM;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder /* remove homedir on user creation? */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (!remove_home) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = confdb_get_bool(confdb, mem_ctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder conf_path, CONFDB_LOCAL_REMOVE_HOMEDIR,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DFL_REMOVE_HOMEDIR, &dfl_remove_home);
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder if (ret != EOK) {
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski goto done;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder data->remove_homedir = dfl_remove_home;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder } else {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder data->remove_homedir = (remove_home == DO_REMOVE_HOME);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* a directory to remove mail spools from */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = confdb_get_string(confdb, mem_ctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder conf_path, CONFDB_LOCAL_MAIL_DIR,
9d500b1d6d1946f9e6f0c1f9ee548a611b3166b0Christian Maeder DFL_MAIL_DIR, &data->maildir);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (ret != EOK) {
1c8c2b04b40b5c054da07b8d059e5ef29d4dbc32Christian Maeder goto done;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski ret = EOK;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maederdone:
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder talloc_free(conf_path);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder return ret;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder}
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder/*
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder * Default values for add operations
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederint useradd_defaults(TALLOC_CTX *mem_ctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct confdb_ctx *confdb,
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder struct ops_ctx *data,
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder const char *gecos,
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder const char *homedir,
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder const char *shell,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int create_home,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder const char *skeldir)
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder{
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int ret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder char *basedir = NULL;
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder char *conf_path = NULL;
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder conf_path = talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL, data->domain->name);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (!conf_path) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return ENOMEM;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* gecos */
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder data->gecos = talloc_strdup(mem_ctx, gecos ? gecos : data->name);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (!data->gecos) {
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski ret = ENOMEM;
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski goto done;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder DEBUG(7, ("Gecos: %s\n", data->gecos));
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
d210b655b5f93a0fff2eefbb94c072d450cef3b4Till Mossakowski /* homedir */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder if (homedir) {
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder data->home = talloc_strdup(data, homedir);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder } else {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder ret = confdb_get_string(confdb, mem_ctx,
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski conf_path, CONFDB_LOCAL_DEFAULT_BASEDIR,
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski DFL_BASEDIR_VAL, &basedir);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder if (ret != EOK) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder goto done;
e3c9174a782e90f965a0b080c22861c3ef5af12dTill Mossakowski }
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder data->home = talloc_asprintf(mem_ctx, "%s/%s", basedir, data->name);
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski }
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski if (!data->home) {
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = ENOMEM;
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski goto done;
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski }
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder DEBUG(7, ("Homedir: %s\n", data->home));
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder /* default shell */
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder if (!shell) {
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski ret = confdb_get_string(confdb, mem_ctx,
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder conf_path, CONFDB_LOCAL_DEFAULT_SHELL,
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski DFL_SHELL_VAL, &data->shell);
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder if (ret != EOK) {
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski goto done;
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder }
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder } else {
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder data->shell = talloc_strdup(mem_ctx, shell);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder if (!data->shell) {
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder ret = ENOMEM;
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski goto done;
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski DEBUG(7, ("Shell: %s\n", data->shell));
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* create homedir on user creation? */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder if (!create_home) {
5b1394673f35f4d23cfe08175841ab414a39678eMarkus Roggenbach ret = confdb_get_bool(confdb, mem_ctx,
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder conf_path, CONFDB_LOCAL_CREATE_HOMEDIR,
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder DFL_CREATE_HOMEDIR, &data->create_homedir);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder if (ret != EOK) {
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder goto done;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder } else {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder data->create_homedir = (create_home == DO_CREATE_HOME);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder DEBUG(7, ("Auto create homedir: %s\n", data->create_homedir?"True":"False"));
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder /* umask to create homedirs */
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder ret = confdb_get_int(confdb, mem_ctx,
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder conf_path, CONFDB_LOCAL_UMASK,
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder DFL_UMASK, (int *) &data->umask);
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder if (ret != EOK) {
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder goto done;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
c40f5b4da5caf568cf9cc6e81c79613450e321aeChristian Maeder DEBUG(7, ("Umask: %o\n", data->umask));
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder /* a directory to create mail spools in */
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = confdb_get_string(confdb, mem_ctx,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder conf_path, CONFDB_LOCAL_MAIL_DIR,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DFL_MAIL_DIR, &data->maildir);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (ret != EOK) {
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder goto done;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder DEBUG(7, ("Mail dir: %s\n", data->maildir));
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* skeleton dir */
627ed7abdbae641636a2d0f2510c0d450f5ee915Christian Maeder if (!skeldir) {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder ret = confdb_get_string(confdb, mem_ctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder conf_path, CONFDB_LOCAL_SKEL_DIR,
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder DFL_SKEL_DIR, &data->skeldir);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (ret != EOK) {
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder goto done;
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder }
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder } else {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder data->skeldir = talloc_strdup(mem_ctx, skeldir);
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder if (!data->skeldir) {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder ret = ENOMEM;
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder goto done;
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder }
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder }
9efe0bf51725355f7a8be26dd44bb6a69212e7beChristian Maeder DEBUG(7, ("Skeleton dir: %s\n", data->skeldir));
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = EOK;
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maederdone:
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder talloc_free(basedir);
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder talloc_free(conf_path);
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder return ret;
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder}
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder/*
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder * Public interface for adding users
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederint useradd(TALLOC_CTX *mem_ctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct sysdb_ctx *sysdb,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct ops_ctx *data)
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder{
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int ret;
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder
627ed7abdbae641636a2d0f2510c0d450f5ee915Christian Maeder ret = sysdb_add_user(mem_ctx, sysdb,
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder data->domain, data->name, data->uid, data->gid,
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder data->gecos, data->home, data->shell, NULL, 0);
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder if (ret) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder goto done;
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder }
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski if (data->addgroups) {
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski struct ldb_dn *member_dn;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder member_dn = sysdb_user_dn(sysdb, mem_ctx,
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski data->domain->name, data->name);
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski if (!member_dn) {
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski ret = ENOMEM;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder goto done;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski if (ret) {
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski goto done;
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_PASSWD);
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowskidone:
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder return ret;
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowski}
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder/*
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder * Public interface for deleting users
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder */
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederint userdel(TALLOC_CTX *mem_ctx,
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder struct sysdb_ctx *sysdb,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder struct ops_ctx *data)
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder{
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder struct ldb_dn *user_dn;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder int ret;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder user_dn = sysdb_user_dn(sysdb, mem_ctx,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder data->domain->name, data->name);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (!user_dn) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(1, ("Could not construct a user DN\n"));
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return ENOMEM;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
62607bfd8541a700d18aee4f9cdb037aded5ab0bChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = sysdb_delete_entry(sysdb, user_dn, false);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (ret) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(2, ("Removing user failed: %s (%d)\n", strerror(ret), ret));
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_PASSWD);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder return ret;
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder}
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder/*
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder * Public interface for adding groups
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder */
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maederint groupadd(TALLOC_CTX *mem_ctx,
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder struct sysdb_ctx *sysdb,
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder struct ops_ctx *data)
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder{
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder int ret;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = sysdb_add_group(mem_ctx, sysdb,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder data->domain, data->name,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder data->gid, NULL, 0);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (ret == EOK) {
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder }
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return ret;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder}
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder/*
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder * Public interface for deleting groups
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder */
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederint groupdel(TALLOC_CTX *mem_ctx,
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder struct sysdb_ctx *sysdb,
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder struct ops_ctx *data)
7bf4436b6f9987b070033a323757b206c898c1beChristian Maeder{
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder struct ldb_dn *group_dn;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder int ret;
0c2a90cbfb63865ff485c3fbe20a14589a5914beTill Mossakowski
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder group_dn = sysdb_group_dn(sysdb, mem_ctx,
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder data->domain->name, data->name);
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski if (group_dn == NULL) {
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski DEBUG(1, ("Could not construct a group DN\n"));
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder return ENOMEM;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ret = sysdb_delete_entry(sysdb, group_dn, false);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder if (ret) {
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder DEBUG(2, ("Removing group failed: %s (%d)\n", strerror(ret), ret));
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return ret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder}
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder/*
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * getpwnam, getgrnam and friends
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder */
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maederint sysdb_getpwnam_sync(TALLOC_CTX *mem_ctx,
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder struct tevent_context *ev,
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder struct sysdb_ctx *sysdb,
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder const char *name,
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder struct sss_domain_info *domain,
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder struct ops_ctx *out)
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder{
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder struct ldb_result *res;
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder const char *str;
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder int ret;
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ret = sysdb_getpwnam(mem_ctx, sysdb, domain, name, &res);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder if (ret) {
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder return ret;
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder }
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder switch (res->count) {
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder case 0:
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder DEBUG(1, ("No result for sysdb_getpwnam call\n"));
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder return ENOENT;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder case 1:
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* fill ops_ctx */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder out->uid = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_UIDNUM, 0);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder out->gid = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_GIDNUM, 0);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder out->name = talloc_strdup(out, str);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder if (out->name == NULL) {
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder return ENOMEM;
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder }
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_GECOS, NULL);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder out->gecos = talloc_strdup(out, str);
587fb54160b66128cf17e4c9bca7494a7f2c3c4aChristian Maeder if (out->gecos == NULL) {
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder return ENOMEM;
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder }
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_HOMEDIR, NULL);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder out->home = talloc_strdup(out, str);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder if (out->home == NULL) {
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder return ENOMEM;
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder }
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, NULL);
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder out->shell = talloc_strdup(out, str);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if (out->shell == NULL) {
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder return ENOMEM;
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder }
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_DISABLED, NULL);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if (str == NULL) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder out->lock = DO_UNLOCK;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski } else {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (strcasecmp(str, "true") == 0) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder out->lock = DO_LOCK;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder } else if (strcasecmp(str, "false") == 0) {
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder out->lock = DO_UNLOCK;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski } else { /* Invalid value */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder DEBUG(2, ("Invalid value for %s attribute: %s\n",
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder SYSDB_DISABLED, str ? str : "NULL"));
4cb77926a2d85ce3bb32ac0938f0100c8c528dc2Till Mossakowski return EIO;
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder }
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder }
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder break;
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder default:
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder DEBUG(1, ("More than one result for sysdb_getpwnam call\n"));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return EIO;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder return EOK;
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski}
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowskiint sysdb_getgrnam_sync(TALLOC_CTX *mem_ctx,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski struct tevent_context *ev,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski struct sysdb_ctx *sysdb,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder const char *name,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct sss_domain_info *domain,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct ops_ctx *out)
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder{
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder struct ldb_result *res;
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder const char *str;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder int ret;
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder ret = sysdb_getgrnam(mem_ctx, sysdb, domain, name, &res);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder if (ret) {
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder return ret;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski switch (res->count) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder case 0:
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DEBUG(1, ("No result for sysdb_getgrnam call\n"));
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder return ENOENT;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski case 1:
64601796d2f62ffe61e9a5340dc569dd41dc2244Christian Maeder /* fill ops_ctx */
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski out->gid = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_GIDNUM, 0);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski out->name = talloc_strdup(out, str);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder if (out->name == NULL) {
e24d81c69aecd41abb2f4969519c9e7126b1d687Christian Maeder return ENOMEM;
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski }
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski break;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski default:
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder DEBUG(1, ("More than one result for sysdb_getgrnam call\n"));
e24d81c69aecd41abb2f4969519c9e7126b1d687Christian Maeder return EIO;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
7bf4436b6f9987b070033a323757b206c898c1beChristian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder return EOK;
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski}
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski