Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/lib/idmap_cache.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "idmap_cache.h"
     22#include "../libcli/security/security.h"
    2123
    2224/**
     
    259261        }
    260262}
     263
     264static char* key_xid2sid_str(TALLOC_CTX* mem_ctx, char t, const char* id) {
     265        return talloc_asprintf(mem_ctx, "IDMAP/%cID2SID/%s", t, id);
     266}
     267
     268static char* key_xid2sid(TALLOC_CTX* mem_ctx, char t, int id) {
     269        char str[32];
     270        snprintf(str, sizeof(str), "%d", id);
     271        return key_xid2sid_str(mem_ctx, t, str);
     272}
     273
     274static char* key_sid2xid_str(TALLOC_CTX* mem_ctx, char t, const char* sid) {
     275        return talloc_asprintf(mem_ctx, "IDMAP/SID2%cID/%s", t, sid);
     276}
     277
     278/* static char* key_sid2xid(TALLOC_CTX* mem_ctx, char t, const struct dom_sid* sid) */
     279/* { */
     280/*      char* sid_str = sid_string_talloc(mem_ctx, sid); */
     281/*      char* key = key_sid2xid_str(mem_ctx, t, sid_str); */
     282/*      talloc_free(sid_str); */
     283/*      return key; */
     284/* } */
     285
     286static bool idmap_cache_del_xid(char t, int xid)
     287{
     288        TALLOC_CTX* mem_ctx = talloc_stackframe();
     289        const char* key = key_xid2sid(mem_ctx, t, xid);
     290        char* sid_str = NULL;
     291        time_t timeout;
     292        bool ret = true;
     293
     294        if (!gencache_get(key, &sid_str, &timeout)) {
     295                DEBUG(3, ("no entry: %s\n", key));
     296                ret = false;
     297                goto done;
     298        }
     299
     300        if (sid_str[0] != '-') {
     301                const char* sid_key = key_sid2xid_str(mem_ctx, t, sid_str);
     302                if (!gencache_del(sid_key)) {
     303                        DEBUG(2, ("failed to delete: %s\n", sid_key));
     304                        ret = false;
     305                } else {
     306                        DEBUG(5, ("delete: %s\n", sid_key));
     307                }
     308
     309        }
     310
     311        if (!gencache_del(key)) {
     312                DEBUG(1, ("failed to delete: %s\n", key));
     313                ret = false;
     314        } else {
     315                DEBUG(5, ("delete: %s\n", key));
     316        }
     317
     318done:
     319        talloc_free(mem_ctx);
     320        return ret;
     321}
     322
     323bool idmap_cache_del_uid(uid_t uid) {
     324        return idmap_cache_del_xid('U', uid);
     325}
     326
     327bool idmap_cache_del_gid(gid_t gid) {
     328        return idmap_cache_del_xid('G', gid);
     329}
     330
     331static bool idmap_cache_del_sid2xid(TALLOC_CTX* mem_ctx, char t, const char* sid)
     332{
     333        const char* sid_key = key_sid2xid_str(mem_ctx, t, sid);
     334        char* xid_str;
     335        time_t timeout;
     336        bool ret = true;
     337
     338        if (!gencache_get(sid_key, &xid_str, &timeout)) {
     339                ret = false;
     340                goto done;
     341        }
     342
     343        if (atoi(xid_str) != -1) {
     344                const char* xid_key = key_xid2sid_str(mem_ctx, t, xid_str);
     345                if (!gencache_del(xid_key)) {
     346                        DEBUG(2, ("failed to delete: %s\n", xid_key));
     347                        ret = false;
     348                } else {
     349                        DEBUG(5, ("delete: %s\n", xid_key));
     350                }
     351        }
     352
     353        if (!gencache_del(sid_key)) {
     354                DEBUG(2, ("failed to delete: %s\n", sid_key));
     355                ret = false;
     356        } else {
     357                DEBUG(5, ("delete: %s\n", sid_key));
     358        }
     359done:
     360        return ret;
     361}
     362
     363bool idmap_cache_del_sid(const struct dom_sid *sid)
     364{
     365        TALLOC_CTX* mem_ctx = talloc_stackframe();
     366        const char* sid_str = sid_string_talloc(mem_ctx, sid);
     367        bool ret = true;
     368
     369        if (!idmap_cache_del_sid2xid(mem_ctx, 'U', sid_str) &&
     370            !idmap_cache_del_sid2xid(mem_ctx, 'G', sid_str))
     371        {
     372                DEBUG(3, ("no entry: %s\n", key_xid2sid_str(mem_ctx, '?', sid_str)));
     373                ret = false;
     374        }
     375
     376        talloc_free(mem_ctx);
     377        return ret;
     378}
Note: See TracChangeset for help on using the changeset viewer.