関数 | |
char * | add_suffix (const char *name, const char *suffix) |
static int | copy_fn (TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) |
static int | test_fn (TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) |
int | backup_tdb (const char *old_name, const char *new_name, int hash_size) |
int | verify_tdb (const char *fname, const char *bak_name) |
変数 | |
static int | failed |
char* add_suffix | ( | const char * | name, | |
const char * | suffix | |||
) |
参照先 fprintf()・len・snprintf().
参照元 backup_tdb()・main().
00063 { 00064 char *ret; 00065 int len = strlen(name) + strlen(suffix) + 1; 00066 ret = (char *)malloc(len); 00067 if (!ret) { 00068 fprintf(stderr,"Out of memory!\n"); 00069 exit(1); 00070 } 00071 snprintf(ret, len, "%s%s", name, suffix); 00072 return ret; 00073 }
static int copy_fn | ( | TDB_CONTEXT * | tdb, | |
TDB_DATA | key, | |||
TDB_DATA | dbuf, | |||
void * | state | |||
) | [static] |
参照先 failed・fprintf()・tdb_name()・tdb_store().
参照元 backup_tdb()・sync_files().
00076 { 00077 TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state; 00078 00079 if (tdb_store(tdb_new, key, dbuf, TDB_INSERT) != 0) { 00080 fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb_new)); 00081 failed = 1; 00082 return 1; 00083 } 00084 return 0; 00085 }
static int test_fn | ( | TDB_CONTEXT * | tdb, | |
TDB_DATA | key, | |||
TDB_DATA | dbuf, | |||
void * | state | |||
) | [static] |
int backup_tdb | ( | const char * | old_name, | |
const char * | new_name, | |||
int | hash_size | |||
) |
参照先 add_suffix()・copy_fn()・failed・fprintf()・printf()・tdb・tdb_close()・tdb_fd()・tdb_hash_size()・tdb_lockall()・tdb_open()・tdb_traverse()・test_fn().
参照元 idmap_tdb_upgrade()・main()・verify_tdb().
00099 { 00100 TDB_CONTEXT *tdb; 00101 TDB_CONTEXT *tdb_new; 00102 char *tmp_name; 00103 struct stat st; 00104 int count1, count2; 00105 00106 tmp_name = add_suffix(new_name, ".tmp"); 00107 00108 /* stat the old tdb to find its permissions */ 00109 if (stat(old_name, &st) != 0) { 00110 perror(old_name); 00111 free(tmp_name); 00112 return 1; 00113 } 00114 00115 /* open the old tdb */ 00116 tdb = tdb_open(old_name, 0, 0, O_RDWR, 0); 00117 if (!tdb) { 00118 printf("Failed to open %s\n", old_name); 00119 free(tmp_name); 00120 return 1; 00121 } 00122 00123 /* create the new tdb */ 00124 unlink(tmp_name); 00125 tdb_new = tdb_open(tmp_name, 00126 hash_size ? hash_size : tdb_hash_size(tdb), 00127 TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL, 00128 st.st_mode & 0777); 00129 if (!tdb_new) { 00130 perror(tmp_name); 00131 free(tmp_name); 00132 return 1; 00133 } 00134 00135 /* lock the old tdb */ 00136 if (tdb_lockall(tdb) != 0) { 00137 fprintf(stderr,"Failed to lock %s\n", old_name); 00138 tdb_close(tdb); 00139 tdb_close(tdb_new); 00140 unlink(tmp_name); 00141 free(tmp_name); 00142 return 1; 00143 } 00144 00145 failed = 0; 00146 00147 /* traverse and copy */ 00148 count1 = tdb_traverse(tdb, copy_fn, (void *)tdb_new); 00149 if (count1 < 0 || failed) { 00150 fprintf(stderr,"failed to copy %s\n", old_name); 00151 tdb_close(tdb); 00152 tdb_close(tdb_new); 00153 unlink(tmp_name); 00154 free(tmp_name); 00155 return 1; 00156 } 00157 00158 /* close the old tdb */ 00159 tdb_close(tdb); 00160 00161 /* close the new tdb and re-open read-only */ 00162 tdb_close(tdb_new); 00163 tdb_new = tdb_open(tmp_name, 0, TDB_DEFAULT, O_RDONLY, 0); 00164 if (!tdb_new) { 00165 fprintf(stderr,"failed to reopen %s\n", tmp_name); 00166 unlink(tmp_name); 00167 perror(tmp_name); 00168 free(tmp_name); 00169 return 1; 00170 } 00171 00172 /* traverse the new tdb to confirm */ 00173 count2 = tdb_traverse(tdb_new, test_fn, 0); 00174 if (count2 != count1) { 00175 fprintf(stderr,"failed to copy %s\n", old_name); 00176 tdb_close(tdb_new); 00177 unlink(tmp_name); 00178 free(tmp_name); 00179 return 1; 00180 } 00181 00182 /* make sure the new tdb has reached stable storage */ 00183 fsync(tdb_fd(tdb_new)); 00184 00185 /* close the new tdb and rename it to .bak */ 00186 tdb_close(tdb_new); 00187 unlink(new_name); 00188 if (rename(tmp_name, new_name) != 0) { 00189 perror(new_name); 00190 free(tmp_name); 00191 return 1; 00192 } 00193 00194 free(tmp_name); 00195 00196 return 0; 00197 }
int verify_tdb | ( | const char * | fname, | |
const char * | bak_name | |||
) |
参照先 backup_tdb()・printf()・tdb・tdb_close()・tdb_open()・tdb_traverse()・test_fn().
参照元 main().
00205 { 00206 TDB_CONTEXT *tdb; 00207 int count = -1; 00208 00209 /* open the tdb */ 00210 tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); 00211 00212 /* traverse the tdb, then close it */ 00213 if (tdb) { 00214 count = tdb_traverse(tdb, test_fn, NULL); 00215 tdb_close(tdb); 00216 } 00217 00218 /* count is < 0 means an error */ 00219 if (count < 0) { 00220 printf("restoring %s\n", fname); 00221 return backup_tdb(bak_name, fname, 0); 00222 } 00223 00224 printf("%s : %d records\n", fname, count); 00225 00226 return 0; 00227 }
int failed [static] |
参照元 _nss_winbind_gidtosid()・_nss_winbind_nametosid()・_nss_winbind_sidtogid()・_nss_winbind_sidtoname()・_nss_winbind_sidtouid()・_nss_winbind_uidtosid()・_pam_compose_pwd_restriction_string()・ads_change_trust_account_password()・ads_get_attrname_by_oid()・ads_sasl_gssapi_bind()・ads_sasl_spnego_bind()・backup_tdb()・cacl_set()・change_trust_account_password()・cli_get_server_name()・cli_krb5_get_ticket()・convert_fn()・copy_fn()・dn_lookup()・getpwsid_sid2gid_recv()・idmap_cache_fill_map()・idmap_rid_initialize()・idmap_tdb_convert()・idmap_tdb_db_init()・net_sam_provision()・pytdbunpack()・pytdbunpack_buffer()・query_name_timeout_response()・smbc_add_cached_server()・smbc_server()・smbldap_search_domain_info()・socketpair_tcp()・tdb_append()・winbindd_dual_pam_auth_cached()・winbindd_pam_logoff()・winbindd_raw_kerberos_login().