Changeset 77 for trunk/samba/source/utils/status.c
- Timestamp:
- Sep 30, 2007, 3:42:50 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/samba/source/utils/status.c
r30 r77 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2of the License, or8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 … … 15 15 16 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 18 20 19 Revision History: … … 36 35 #define SMB_MAXPIDS 2048 37 36 static uid_t Ucrit_uid = 0; /* added by OH */ 38 static pid_tUcrit_pid[SMB_MAXPIDS]; /* Ugly !!! */ /* added by OH */37 static struct server_id Ucrit_pid[SMB_MAXPIDS]; /* Ugly !!! */ /* added by OH */ 39 38 static int Ucrit_MaxPid=0; /* added by OH */ 40 39 static unsigned int Ucrit_IsActive = 0; /* added by OH */ … … 70 69 } 71 70 72 static unsigned int Ucrit_checkPid( pid_tpid)71 static unsigned int Ucrit_checkPid(struct server_id pid) 73 72 { 74 73 int i; … … 78 77 79 78 for (i=0;i<Ucrit_MaxPid;i++) { 80 if ( pid == Ucrit_pid[i])79 if (cluster_id_equal(&pid, &Ucrit_pid[i])) 81 80 return 1; 82 81 } … … 85 84 } 86 85 87 static BOOL Ucrit_addPid( pid_tpid )86 static BOOL Ucrit_addPid( struct server_id pid ) 88 87 { 89 88 if ( !Ucrit_IsActive ) … … 113 112 } 114 113 114 if (!process_exists(e->pid)) { 115 return; 116 } 117 115 118 if (count==0) { 116 119 d_printf("Locked files:\n"); … … 120 123 count++; 121 124 122 if (Ucrit_checkPid( procid_to_pid(&e->pid))) {125 if (Ucrit_checkPid(e->pid)) { 123 126 d_printf("%-11s ",procid_str_static(&e->pid)); 124 127 d_printf("%-9u ", (unsigned int)e->uid); … … 167 170 } 168 171 169 static void print_brl(SMB_DEV_T dev, 170 SMB_INO_T ino, 171 struct process_id pid, 172 static void print_brl(struct file_id id, 173 struct server_id pid, 172 174 enum brl_type lock_type, 173 175 enum brl_flavour lock_flav, 174 176 br_off start, 175 br_off size) 177 br_off size, 178 void *private_data) 176 179 { 177 180 static int count; 181 int i; 182 static const struct { 183 enum brl_type lock_type; 184 const char *desc; 185 } lock_types[] = { 186 { READ_LOCK, "R" }, 187 { WRITE_LOCK, "W" }, 188 { PENDING_READ_LOCK, "PR" }, 189 { PENDING_WRITE_LOCK, "PW" }, 190 { UNLOCK_LOCK, "U" } 191 }; 192 const char *desc="X"; 193 const char *sharepath = ""; 194 const char *fname = ""; 195 struct share_mode_lock *share_mode; 196 178 197 if (count==0) { 179 198 d_printf("Byte range locks:\n"); 180 d_printf(" Pid dev:inode R/W start size\n");181 d_printf("------------------------------------------------ \n");199 d_printf("Pid dev:inode R/W start size SharePath Name\n"); 200 d_printf("--------------------------------------------------------------------------------\n"); 182 201 } 183 202 count++; 184 203 185 d_printf("%8s %05x:%05x %s %9.0f %9.0f\n", 186 procid_str_static(&pid), (int)dev, (int)ino, 187 lock_type==READ_LOCK?"R":"W", 188 (double)start, (double)size); 189 } 190 191 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) 192 { 193 struct connections_data crec; 194 195 if (dbuf.dsize != sizeof(crec)) 204 share_mode = fetch_share_mode_unlocked(NULL, id, "__unspecified__", "__unspecified__"); 205 if (share_mode) { 206 sharepath = share_mode->servicepath; 207 fname = share_mode->filename; 208 } 209 210 for (i=0;i<ARRAY_SIZE(lock_types);i++) { 211 if (lock_type == lock_types[i].lock_type) { 212 desc = lock_types[i].desc; 213 } 214 } 215 216 d_printf("%-10s %-15s %-4s %-9.0f %-9.0f %-24s %-24s\n", 217 procid_str_static(&pid), file_id_string_tos(&id), 218 desc, 219 (double)start, (double)size, 220 sharepath, fname); 221 222 TALLOC_FREE(share_mode); 223 } 224 225 static int traverse_fn1(struct db_record *rec, 226 const struct connections_key *key, 227 const struct connections_data *crec, 228 void *state) 229 { 230 if (crec->cnum == -1) 196 231 return 0; 197 232 198 memcpy(&crec, dbuf.dptr, sizeof(crec)); 199 200 if (crec.cnum == -1) 233 if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) { 201 234 return 0; 202 203 if (!process_exists(crec.pid) || !Ucrit_checkUid(crec.uid)) {204 return 0;205 235 } 206 236 207 237 d_printf("%-10s %s %-12s %s", 208 crec.servicename,procid_str_static(&crec.pid),209 crec.machine,210 time_to_asc(crec.start));238 crec->servicename,procid_str_static(&crec->pid), 239 crec->machine, 240 time_to_asc(crec->start)); 211 241 212 242 return 0; 213 243 } 214 244 215 static int traverse_sessionid( TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)245 static int traverse_sessionid(struct db_record *db, void *state) 216 246 { 217 247 struct sessionid sessionid; 218 248 fstring uid_str, gid_str; 219 249 220 if (db uf.dsize != sizeof(sessionid))250 if (db->value.dsize != sizeof(sessionid)) 221 251 return 0; 222 252 223 memcpy(&sessionid, db uf.dptr, sizeof(sessionid));224 225 if (!process_exists _by_pid(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) {253 memcpy(&sessionid, db->value.dptr, sizeof(sessionid)); 254 255 if (!process_exists(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) { 226 256 return 0; 227 257 } … … 232 262 fstr_sprintf(gid_str, "%d", sessionid.gid); 233 263 234 d_printf("% 5d%-12s %-12s %-12s (%s)\n",235 (int)sessionid.pid,264 d_printf("%-7s %-12s %-12s %-12s (%s)\n", 265 procid_str_static(&sessionid.pid), 236 266 numeric_only ? uid_str : uidtoname(sessionid.uid), 237 267 numeric_only ? gid_str : gidtoname(sessionid.gid), … … 248 278 int c; 249 279 int profile_only = 0; 250 TDB_CONTEXT *tdb;251 280 BOOL show_processes, show_locks, show_shares; 252 281 poptContext pc; … … 266 295 POPT_TABLEEND 267 296 }; 297 TALLOC_CTX *frame = talloc_stackframe(); 298 int ret = 0; 268 299 269 300 sec_init(); … … 276 307 if (getuid() != geteuid()) { 277 308 d_printf("smbstatus should not be run setuid\n"); 278 return(1); 309 ret = 1; 310 goto done; 279 311 } 280 312 … … 308 340 if (!lp_load(dyn_CONFIGFILE,False,False,False,True)) { 309 341 fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); 310 return (-1); 311 } 312 342 ret = -1; 343 goto done; 344 } 345 346 /* 347 * This implicitly initializes the global ctdbd connection, usable by 348 * the db_open() calls further down. 349 */ 350 351 messaging_init(NULL, procid_self(), event_context_init(NULL)); 352 313 353 switch (profile_only) { 314 354 case 'P': … … 323 363 324 364 if ( show_processes ) { 325 tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); 326 if (!tdb) { 365 struct db_context *db; 366 db = db_open(NULL, lock_path("sessionid.tdb"), 0, 367 TDB_DEFAULT, O_RDWR, 0644); 368 if (!db) { 327 369 d_printf("sessionid.tdb not initialised\n"); 328 370 } else { … … 331 373 d_printf("-------------------------------------------------------------------\n"); 332 374 333 tdb_traverse(tdb, traverse_sessionid, NULL); 334 tdb_close(tdb); 335 } 336 337 if (processes_only) 338 exit(0); 375 db->traverse_read(db, traverse_sessionid, NULL); 376 TALLOC_FREE(db); 377 } 378 379 if (processes_only) { 380 goto done; 381 } 339 382 } 340 383 341 384 if ( show_shares ) { 342 tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); 343 if (!tdb) { 344 d_printf("%s not initialised\n", lock_path("connections.tdb")); 345 d_printf("This is normal if an SMB client has never connected to your server.\n"); 346 } else { 347 if (verbose) { 348 d_printf("Opened %s\n", lock_path("connections.tdb")); 349 } 350 351 if (brief) 352 exit(0); 385 if (verbose) { 386 d_printf("Opened %s\n", lock_path("connections.tdb")); 387 } 388 389 if (brief) { 390 goto done; 391 } 353 392 354 d_printf("\nService pid machine Connected at\n"); 355 d_printf("-------------------------------------------------------\n"); 356 357 tdb_traverse(tdb, traverse_fn1, NULL); 358 tdb_close(tdb); 359 360 d_printf("\n"); 361 } 362 363 if ( shares_only ) 364 exit(0); 393 d_printf("\nService pid machine Connected at\n"); 394 d_printf("-------------------------------------------------------\n"); 395 396 connections_forall(traverse_fn1, NULL); 397 398 d_printf("\n"); 399 400 if ( shares_only ) { 401 goto done; 402 } 365 403 } 366 404 367 405 if ( show_locks ) { 368 int re t;406 int result; 369 407 370 408 if (!locking_init(1)) { 371 409 d_printf("Can't initialise locking module - exiting\n"); 372 exit(1); 410 ret = 1; 411 goto done; 373 412 } 374 413 375 re t = share_mode_forall(print_share_mode, NULL);376 377 if (re t == 0) {414 result = share_mode_forall(print_share_mode, NULL); 415 416 if (result == 0) { 378 417 d_printf("No locked files\n"); 379 } else if (re t == -1) {418 } else if (result == -1) { 380 419 d_printf("locked file list truncated\n"); 381 420 } … … 384 423 385 424 if (show_brl) { 386 brl_forall(print_brl );425 brl_forall(print_brl, NULL); 387 426 } 388 427 … … 390 429 } 391 430 392 return (0); 393 } 431 done: 432 TALLOC_FREE(frame); 433 return ret; 434 }
Note:
See TracChangeset
for help on using the changeset viewer.