af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke Benjamin Franzke <benjaminfranzke@googlemail.com>
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke Copyright (C) 2013 Benjamin Franzke
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke This program is free software; you can redistribute it and/or modify
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke it under the terms of the GNU General Public License as published by
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke the Free Software Foundation; either version 3 of the License, or
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke (at your option) any later version.
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke This program is distributed in the hope that it will be useful,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke but WITHOUT ANY WARRANTY; without even the implied warranty of
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke GNU General Public License for more details.
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke You should have received a copy of the GNU General Public License
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke along with this program. If not, see <http://www.gnu.org/licenses/>.
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke/* TODO: Support of [all] samba's Unix SIDs:
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * Users: S-1-22-1-%UID
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * Groups: S-1-22-2-%GID
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkeint cifs_idmap_init_plugin(void **handle, const char **errmsg)
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke err = sss_idmap_init(NULL, NULL, NULL, &ctx->idmap);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke ctx_set_error(ctx, idmap_error_string(err));
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke/* Test with `getcifsacl file` on client. */
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkeint cifs_idmap_sid_to_str(void *handle, const struct cifs_sid *csid,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke iderr = sss_idmap_bin_sid_to_sid(ctx->idmap, (const uint8_t *) csid,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke ctx_set_error(ctx, idmap_error_string(iderr));
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke err = sss_nss_getnamebysid(sid, name, &id_type);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke /* FIXME: Map Samba Unix SIDs? (sid->id and use getpwuid)? */
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkestatic int sid_to_cifs_sid(struct sssd_ctx *ctx, const char *sid,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke ctx_set_error(ctx, idmap_error_string(err));
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke ctx_set_error(ctx, "too large sid length");
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke/* Test with setcifsacl -a */
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkeint cifs_idmap_str_to_sid(void *handle, const char *name,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke err = sss_nss_getsidbyname(name, &sid, &id_type);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke /* Might be a raw string representation of SID,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * try converting that before returning an error. */
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkestatic int samba_unix_sid_to_id(const char *sid, struct cifs_uxid *cuxid)
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke if (sscanf(sid, "S-1-22-%hhu-%u", &type, &id) != 2)
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkestatic int sss_sid_to_id(struct sssd_ctx *ctx, const char *sid,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke err = sss_nss_getidbysid(sid, (uint32_t *)&cuxid->id.uid, &id_type);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * cifs_idmap_sids_to_ids - convert struct cifs_sids to struct cifs_uxids
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * usecase: mount.cifs -o sec=krb5,multiuser,cifsacl,nounix
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * test: ls -n on mounted share
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkeint cifs_idmap_sids_to_ids(void *handle, const struct cifs_sid *csid,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke for (i = 0; i < num; ++i) {
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke err = sss_idmap_bin_sid_to_sid(ctx->idmap, (const uint8_t *) &csid[i],
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke ctx_set_error(ctx, idmap_error_string(err));
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke if (sss_sid_to_id(ctx, sid, &cuxid[i]) == 0 ||
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke samba_unix_sid_to_id(sid, &cuxid[i]) == 0) {
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke debug("setting uid of %s to %d", sid, cuxid[i].id.uid);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzkeint cifs_idmap_ids_to_sids(void *handle, const struct cifs_uxid *cuxid,
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke for (i = 0; i < num; ++i) {
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke err = sss_nss_getsidbyid((uint32_t)cuxid[i].id.uid, &sid, &id_type);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke /* FIXME: would it be safe to map *any* uid/gids unknown by sssd to
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * SAMBA's UNIX SIDs? */