sss_sync_ops.c revision e5e32021c23f3726d68ee756e8e3de48b3214063
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder Jakub Hrozek <jhrozek@redhat.com>
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder Copyright (C) 2009 Red Hat
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 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.
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/>.
43b4c41fbb07705c9df321221ab9cb9832460407Christian Maeder/* Default settings for user attributes */
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder#define VAR_CHECK(var, val, attr, msg) do { \
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder * Generic modify groups member
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstatic int mod_groups_member(TALLOC_CTX *mem_ctx,
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder/* FIXME: add transaction around loop */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder for (i = 0; grouplist[i]; i++) {
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder ret = sysdb_mod_group_member(tmpctx, sysdb,
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)
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder * Modify a user
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maederstatic int usermod_build_attrs(TALLOC_CTX *mem_ctx,
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder "Could not add attribute to changeset\n");
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder "Could not add attribute to changeset\n");
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder "Could not add attribute to changeset\n");
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder "Could not add attribute to changeset\n");
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowski "Could not add attribute to changeset\n");
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski "Could not add attribute to changeset\n");
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* PAM code checks for 'false' value in SYSDB_DISABLED attribute */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder "Could not add attribute to changeset\n");
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder * Public interface for modifying users
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder ret = remove_from_groups(mem_ctx, sysdb, data, member_dn);
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder * Public interface for modifying groups
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, data->gid);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = remove_from_groups(mem_ctx, sysdb, data, member_dn);
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder conf_path = talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL, data->domain->name);
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder /* remove homedir on user creation? */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder data->remove_homedir = (remove_home == DO_REMOVE_HOME);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* a directory to remove mail spools from */
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder * Default values for add operations
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder conf_path = talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL, data->domain->name);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder data->gecos = talloc_strdup(mem_ctx, gecos ? gecos : data->name);
d210b655b5f93a0fff2eefbb94c072d450cef3b4Till Mossakowski /* homedir */
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder data->home = talloc_asprintf(mem_ctx, "%s/%s", basedir, data->name);
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder /* default shell */
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder data->shell = talloc_strdup(mem_ctx, shell);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* create homedir on user creation? */
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder DFL_CREATE_HOMEDIR, &data->create_homedir);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder data->create_homedir = (create_home == DO_CREATE_HOME);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder DEBUG(7, ("Auto create homedir: %s\n", data->create_homedir?"True":"False"));
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder /* umask to create homedirs */
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder /* a directory to create mail spools in */
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder DEBUG(7, ("Mail dir: %s\n", data->maildir));
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* skeleton dir */
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder data->skeldir = talloc_strdup(mem_ctx, skeldir);
9efe0bf51725355f7a8be26dd44bb6a69212e7beChristian Maeder DEBUG(7, ("Skeleton dir: %s\n", data->skeldir));
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder * Public interface for adding users
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder data->domain, data->name, data->uid, data->gid,
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder data->gecos, data->home, data->shell, NULL, 0);
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder * Public interface for deleting users
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(1, ("Could not construct a user DN\n"));
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = sysdb_delete_entry(sysdb, user_dn, false);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(2, ("Removing user failed: %s (%d)\n", strerror(ret), ret));
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder * Public interface for adding groups
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder * Public interface for deleting groups
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski DEBUG(1, ("Could not construct a group DN\n"));
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ret = sysdb_delete_entry(sysdb, group_dn, false);
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder DEBUG(2, ("Removing group failed: %s (%d)\n", strerror(ret), ret));
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * getpwnam, getgrnam and friends
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maederint sysdb_getpwnam_sync(TALLOC_CTX *mem_ctx,
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ret = sysdb_getpwnam(mem_ctx, sysdb, domain, name, &res);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder DEBUG(1, ("No result for sysdb_getpwnam call\n"));
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* fill ops_ctx */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder out->uid = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_UIDNUM, 0);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder out->gid = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_GIDNUM, 0);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_GECOS, NULL);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_HOMEDIR, NULL);
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, NULL);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_DISABLED, NULL);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder } else if (strcasecmp(str, "false") == 0) {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski } else { /* Invalid value */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder DEBUG(2, ("Invalid value for %s attribute: %s\n",
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder DEBUG(1, ("More than one result for sysdb_getpwnam call\n"));
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowskiint sysdb_getgrnam_sync(TALLOC_CTX *mem_ctx,
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder ret = sysdb_getgrnam(mem_ctx, sysdb, domain, name, &res);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DEBUG(1, ("No result for sysdb_getgrnam call\n"));
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);
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder DEBUG(1, ("More than one result for sysdb_getgrnam call\n"));