/* * Returns an LDAP error code. */ static int cmp2( LDAP *ld1, LDAP *ld2, LDAPMessage *e1, int findonly) { LDAPMessage *e2, *res; char *dn, *attrcmp; int found=0, rc; ATTR *a1, *a2; dn = ldap_get_dn( ld1, e1 ); if ( ldaptool_verbose ) { if ( findonly ) { printf( "Checking that %s exists on both servers\n", dn ); } else { printf("Comparing entry %s on both servers\n", dn ); } } if ( ldap_search( ld2, dn, LDAP_SCOPE_BASE, "objectClass=*", NULL, 0 ) == -1 ) { return( ldaptool_print_lderror( ld2, "ldap_search", LDAPTOOL_CHECK4SSL_IF_APPROP )); } /* XXXmcs: this code should be modified to display referrals and references */ while ( (rc = ldap_result( ld2, LDAP_RES_ANY, 0, NULL, &res )) == LDAP_RES_SEARCH_ENTRY ) { e2 = ldap_first_entry( ld1, res ); found = 1; if ( !findonly ) { a1 = get_attrs( ld1, e1 ); a2 = get_attrs( ld2, e2 ); attrcmp = cmp_attrs( a1, a2 ); if ( strcmp( attrcmp, "") != 0 ) { printf("\n%s%s\n", dn, attrcmp); } } ldap_msgfree( res ); } if ( !found ) { notfound( dn, findonly ); differ = 1; } if ( rc == -1 ) { return( ldaptool_print_lderror( ld2, "ldap_result", LDAPTOOL_CHECK4SSL_IF_APPROP )); } ldap_msgfree( res ); ldap_memfree( dn ); return(rc); }
nvlist_t * slice_get_attributes(descriptor_t *dp, int *errp) { nvlist_t *attrs = NULL; int fd; char devpath[MAXPATHLEN]; if (!desc_ok(dp)) { *errp = ENODEV; return (NULL); } if (nvlist_alloc(&attrs, NVATTRS, 0) != 0) { *errp = ENOMEM; return (NULL); } /* dp->name is /dev/dsk, need to convert back to /dev/rdsk */ dsk2rdsk(dp->name, devpath, sizeof (devpath)); fd = open(devpath, O_RDONLY|O_NDELAY); if ((*errp = get_attrs(dp, fd, attrs)) != 0) { nvlist_free(attrs); attrs = NULL; } if (fd >= 0) { (void) close(fd); } return (attrs); }
nvlist_t * media_get_attributes(descriptor_t *dp, int *errp) { nvlist_t *attrs = NULL; int fd; if (!desc_ok(dp)) { *errp = ENODEV; return (NULL); } if (nvlist_alloc(&attrs, NVATTRS, 0) != 0) { *errp = ENOMEM; return (NULL); } fd = drive_open_disk(dp->p.disk, NULL, 0); if ((*errp = get_attrs(dp->p.disk, fd, attrs)) != 0) { nvlist_free(attrs); attrs = NULL; } if (fd >= 0) { (void) close(fd); } return (attrs); }
nvlist_t * drive_get_attributes(descriptor_t *dp, int *errp) { nvlist_t *attrs = NULL; int fd; char opath[MAXPATHLEN]; if (nvlist_alloc(&attrs, NVATTRS, 0) != 0) { *errp = ENOMEM; return (NULL); } opath[0] = 0; fd = drive_open_disk(dp->p.disk, opath, sizeof (opath)); if ((*errp = get_attrs(dp->p.disk, fd, opath, attrs)) != 0) { nvlist_free(attrs); attrs = NULL; } if (fd >= 0) { (void) close(fd); } return (attrs); }
const session_string* session::get_buf(const char* name) { if (get_attrs(attrs_) == false) return NULL; std::map<string, session_string>::const_iterator cit = attrs_.find(name); if (cit == attrs_.end()) return NULL; return &cit->second; }
/* enters properties change mode */ void enter_attr_mode(FileView *active_view) { if(curr_stats.load_stage < 2) return; view = active_view; vle_mode_set(ATTR_MODE, VMT_SECONDARY); clear_input_bar(); curr_stats.use_input_bar = 0; init(); get_attrs(); redraw_attr_dialog(); }
bool session::del(const char* name) { // 直接操作后端 cache 服务器,删除属性字段 if (get_attrs(attrs_) == false) return true; std::map<string, session_string>::iterator it = attrs_.find(name); if (it == attrs_.end()) return false; // 先删除并释放对应的对象 attrs_.erase(it); // 如果 sid 中已经没有了数据,则应该将 sid 对象从 memcached 中删除 if (attrs_.empty()) { // 调用虚函数,删除该 sid 对应的缓存内容 if (remove() == false) { logger_error("del sid(%s) error", sid_.c_str()); return false; } return true; } // 重新添加剩余的数据 if (set_attrs(attrs_) == false) { logger_error("set cache error, sid(%s)", sid_.c_str()); attrs_clear(attrs_); // 清除属性集合数据 return false; } attrs_clear(attrs_); // 清除属性集合数据 return true; }
bool session::set(const char* name, const void* value, size_t len) { // 直接操作后端 cache 服务器,设置(添加/修改) 属性字段 // 调用纯虚接口,获得原来的 sid 数据 if (get_attrs(attrs_) == false) { session_string ss(len); ss.copy(value, len); ss.todo_ = TODO_SET; attrs_cache_.insert(std::make_pair(string(name), ss)); } // 如果存在对应 sid 的数据,则将新数据添加在原来数据中 else { if (!sid_saved_) sid_saved_ = true; // 如果该属性已存在,则需要先释放原来的属性值后再添加新值 session_string ss(len); ss.copy(value, len); ss.todo_ = TODO_SET; attrs_cache_.insert(std::make_pair(string(name), ss)); } // 调用纯虚接口,向 memcached 或类似缓存中添加数据 if (set_attrs(attrs_) == false) { logger_error("set cache error, sid(%s)", sid_.c_str()); attrs_clear(attrs_); // 清除属性集合数据 return false; } attrs_clear(attrs_); // 清除属性集合数据 if (!sid_saved_) sid_saved_ = true; return true; }
bool session::flush() { if (!dirty_) return true; dirty_ = false; // 调用纯虚接口,获得原来的 sid 数据 if (get_attrs(attrs_) == true) { if (!sid_saved_) sid_saved_ = true; } std::map<string, session_string>::iterator it_cache = attrs_cache_.begin(); for (; it_cache != attrs_cache_.end(); ++it_cache) { // 如果该属性已存在,则需要先释放原来的属性值后再添加新值 std::map<string, session_string>::iterator it_attr = attrs_.find(it_cache->first); if (it_attr == attrs_.end()) { if (it_cache->second.todo_ == TODO_SET) attrs_.insert(std::make_pair(it_cache->first, it_cache->second)); } else if (it_cache->second.todo_ == TODO_SET) { // 设置新的数据 attrs_.insert(std::make_pair(it_cache->first, it_cache->second)); } else if (it_cache->second.todo_ == TODO_DEL) { attrs_.erase(it_attr); } else { logger_warn("unknown todo(%d)", (int) it_cache->second.todo_); } } // 清除缓存的数据:因为内部的数据已经被添加至 attrs_ 中, // 所以只需要将 attrs_cache_ 空间清除即可 attrs_cache_.clear(); // 调用纯虚接口,向 memcached 或类似缓存中添加数据 if (set_attrs(attrs_) == false) { logger_error("set cache error, sid(%s)", sid_.c_str()); attrs_clear(attrs_); // 清除属性集合数据 return false; } attrs_clear(attrs_); // 清除属性集合数据 if (!sid_saved_) sid_saved_ = true; return true; }