Changeset 988 for vendor/current/source3/utils/status.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/utils/status.c
r860 r988 32 32 33 33 #include "includes.h" 34 #include "smbd/globals.h" 34 35 #include "system/filesys.h" 35 36 #include "popt_common.h" 36 #include "dbwrap.h" 37 #include "dbwrap/dbwrap.h" 38 #include "dbwrap/dbwrap_open.h" 37 39 #include "../libcli/security/security.h" 38 40 #include "session.h" 39 41 #include "locking/proto.h" 40 42 #include "messages.h" 43 #include "librpc/gen_ndr/open_files.h" 44 #include "smbd/smbd.h" 45 #include "librpc/gen_ndr/notify.h" 46 #include "lib/conn_tdb.h" 41 47 #include "serverid.h" 48 #include "status_profile.h" 49 #include "smbd/notifyd/notifyd.h" 42 50 43 51 #define SMB_MAXPIDS 2048 … … 53 61 static bool show_brl; 54 62 static bool numeric_only; 63 static bool do_checks = true; 55 64 56 65 const char *username = NULL; 57 58 extern bool status_profile_dump(bool be_verbose);59 extern bool status_profile_rates(bool be_verbose);60 66 61 67 /* added by OH */ … … 85 91 86 92 for (i=0;i<Ucrit_MaxPid;i++) { 87 if ( cluster_id_equal(&pid, &Ucrit_pid[i]))93 if (serverid_equal(&pid, &Ucrit_pid[i])) { 88 94 return 1; 95 } 89 96 } 90 97 … … 109 116 } 110 117 111 static void print_share_mode(const struct share_mode_entry *e, 112 const char *sharepath, 113 const char *fname, 114 void *dummy) 118 static int print_share_mode(const struct share_mode_entry *e, 119 const char *sharepath, 120 const char *fname, 121 const char *sname, 122 void *dummy) 115 123 { 116 124 static int count; 117 125 118 if (!is_valid_share_mode_entry(e)) { 119 return; 120 } 121 122 if (!process_exists(e->pid)) { 123 return; 126 if (do_checks && !is_valid_share_mode_entry(e)) { 127 return 0; 124 128 } 125 129 … … 131 135 count++; 132 136 137 if (do_checks && !serverid_exists(&e->pid)) { 138 /* the process for this entry does not exist any more */ 139 return 0; 140 } 141 133 142 if (Ucrit_checkPid(e->pid)) { 134 d_printf("%-11s ",procid_str_static(&e->pid)); 143 struct server_id_buf tmp; 144 d_printf("%-11s ", server_id_str_buf(e->pid, &tmp)); 135 145 d_printf("%-9u ", (unsigned int)e->uid); 136 146 switch (map_share_mode_to_deny_mode(e->share_access, … … 170 180 } else if (e->op_type & LEVEL_II_OPLOCK) { 171 181 d_printf("LEVEL_II "); 182 } else if (e->op_type == LEASE_OPLOCK) { 183 uint32_t lstate = e->lease->current_state; 184 d_printf("LEASE(%s%s%s)%s%s%s ", 185 (lstate & SMB2_LEASE_READ)?"R":"", 186 (lstate & SMB2_LEASE_WRITE)?"W":"", 187 (lstate & SMB2_LEASE_HANDLE)?"H":"", 188 (lstate & SMB2_LEASE_READ)?"":" ", 189 (lstate & SMB2_LEASE_WRITE)?"":" ", 190 (lstate & SMB2_LEASE_HANDLE)?"":" "); 172 191 } else { 173 192 d_printf("NONE "); 174 193 } 175 194 176 d_printf(" %s %s %s",sharepath, fname, time_to_asc((time_t)e->time.tv_sec)); 177 } 195 d_printf(" %s %s%s %s", 196 sharepath, fname, 197 sname ? sname : "", 198 time_to_asc((time_t)e->time.tv_sec)); 199 } 200 201 return 0; 178 202 } 179 203 … … 187 211 { 188 212 static int count; 189 int i;213 unsigned int i; 190 214 static const struct { 191 215 enum brl_type lock_type; … … 202 226 char *fname = NULL; 203 227 struct share_mode_lock *share_mode; 228 struct server_id_buf tmp; 204 229 205 230 if (count==0) { … … 212 237 share_mode = fetch_share_mode_unlocked(NULL, id); 213 238 if (share_mode) { 214 bool has_stream = share_mode->stream_name != NULL; 215 216 fname = talloc_asprintf(NULL, "%s%s%s", share_mode->base_name, 239 bool has_stream = share_mode->data->stream_name != NULL; 240 241 fname = talloc_asprintf(NULL, "%s%s%s", 242 share_mode->data->base_name, 217 243 has_stream ? ":" : "", 218 has_stream ? share_mode->stream_name : 244 has_stream ? 245 share_mode->data->stream_name : 219 246 ""); 220 247 } else { … … 231 258 } 232 259 233 d_printf("%-10s %-15s %-4s %-9 .0f %-9.0f %-24s %-24s\n",234 procid_str_static(&pid), file_id_string_tos(&id),260 d_printf("%-10s %-15s %-4s %-9jd %-9jd %-24s %-24s\n", 261 server_id_str_buf(pid, &tmp), file_id_string_tos(&id), 235 262 desc, 236 ( double)start, (double)size,263 (intmax_t)start, (intmax_t)size, 237 264 sharepath, fname); 238 265 … … 241 268 } 242 269 243 static int traverse_fn1(const struct connections_key *key, 244 const struct connections_data *crec, 245 void *state) 246 { 247 if (crec->cnum == -1) 270 static const char *session_dialect_str(uint16_t dialect) 271 { 272 static fstring unkown_dialect; 273 274 switch(dialect){ 275 case SMB2_DIALECT_REVISION_000: 276 return "NT1"; 277 case SMB2_DIALECT_REVISION_202: 278 return "SMB2_02"; 279 case SMB2_DIALECT_REVISION_210: 280 return "SMB2_10"; 281 case SMB2_DIALECT_REVISION_222: 282 return "SMB2_22"; 283 case SMB2_DIALECT_REVISION_224: 284 return "SMB2_24"; 285 case SMB3_DIALECT_REVISION_300: 286 return "SMB3_00"; 287 case SMB3_DIALECT_REVISION_302: 288 return "SMB3_02"; 289 case SMB3_DIALECT_REVISION_310: 290 return "SMB3_10"; 291 case SMB3_DIALECT_REVISION_311: 292 return "SMB3_11"; 293 } 294 295 fstr_sprintf(unkown_dialect, "Unknown (0x%04x)", dialect); 296 return unkown_dialect; 297 } 298 299 static int traverse_connections(const struct connections_key *key, 300 const struct connections_data *crec, 301 void *private_data) 302 { 303 TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data; 304 struct server_id_buf tmp; 305 char *timestr = NULL; 306 int result = 0; 307 const char *encryption = "-"; 308 const char *signing = "-"; 309 310 if (crec->cnum == TID_FIELD_INVALID) 248 311 return 0; 249 312 250 if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) { 313 if (do_checks && 314 (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid))) { 251 315 return 0; 252 316 } 253 317 254 d_printf("%-10s %s %-12s %s", 255 crec->servicename,procid_str_static(&crec->pid), 318 timestr = timestring(mem_ctx, crec->start); 319 if (timestr == NULL) { 320 return -1; 321 } 322 323 if (smbXsrv_is_encrypted(crec->encryption_flags)) { 324 switch (crec->cipher) { 325 case SMB_ENCRYPTION_GSSAPI: 326 encryption = "GSSAPI"; 327 break; 328 case SMB2_ENCRYPTION_AES128_CCM: 329 encryption = "AES-128-CCM"; 330 break; 331 case SMB2_ENCRYPTION_AES128_GCM: 332 encryption = "AES-128-GCM"; 333 break; 334 default: 335 encryption = "???"; 336 result = -1; 337 break; 338 } 339 } 340 341 if (smbXsrv_is_signed(crec->signing_flags)) { 342 if (crec->dialect >= SMB3_DIALECT_REVISION_302) { 343 signing = "AES-128-CMAC"; 344 } else if (crec->dialect >= SMB2_DIALECT_REVISION_202) { 345 signing = "HMAC-SHA256"; 346 } else { 347 signing = "HMAC-MD5"; 348 } 349 } 350 351 d_printf("%-12s %-7s %-13s %-32s %-12s %-12s\n", 352 crec->servicename, server_id_str_buf(crec->pid, &tmp), 256 353 crec->machine, 257 time_to_asc(crec->start)); 258 259 return 0; 354 timestr, 355 encryption, 356 signing); 357 358 TALLOC_FREE(timestr); 359 360 return result; 260 361 } 261 362 … … 263 364 void *private_data) 264 365 { 366 TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data; 265 367 fstring uid_str, gid_str; 266 267 if (!process_exists(session->pid) 268 || !Ucrit_checkUid(session->uid)) { 368 struct server_id_buf tmp; 369 char *machine_hostname = NULL; 370 int result = 0; 371 const char *encryption = "-"; 372 const char *signing = "-"; 373 374 if (do_checks && 375 (!process_exists(session->pid) || 376 !Ucrit_checkUid(session->uid))) { 269 377 return 0; 270 378 } … … 272 380 Ucrit_addPid(session->pid); 273 381 274 fstr_sprintf(uid_str, "%u", (unsigned int)session->uid); 275 fstr_sprintf(gid_str, "%u", (unsigned int)session->gid); 276 277 d_printf("%-7s %-12s %-12s %-12s (%s)\n", 278 procid_str_static(&session->pid), 279 numeric_only ? uid_str : uidtoname(session->uid), 280 numeric_only ? gid_str : gidtoname(session->gid), 281 session->remote_machine, session->hostname); 282 283 return 0; 284 } 285 286 287 288 289 int main(int argc, char *argv[]) 382 fstrcpy(uid_str, "-1"); 383 384 if (session->uid != -1) { 385 if (numeric_only) { 386 fstr_sprintf(uid_str, "%u", (unsigned int)session->uid); 387 } else { 388 fstrcpy(uid_str, uidtoname(session->uid)); 389 } 390 } 391 392 fstrcpy(gid_str, "-1"); 393 394 if (session->gid != -1) { 395 if (numeric_only) { 396 fstr_sprintf(gid_str, "%u", (unsigned int)session->gid); 397 } else { 398 fstrcpy(gid_str, gidtoname(session->gid)); 399 } 400 } 401 402 machine_hostname = talloc_asprintf(mem_ctx, "%s (%s)", 403 session->remote_machine, 404 session->hostname); 405 if (machine_hostname == NULL) { 406 return -1; 407 } 408 409 if (smbXsrv_is_encrypted(session->encryption_flags)) { 410 switch (session->cipher) { 411 case SMB2_ENCRYPTION_AES128_CCM: 412 encryption = "AES-128-CCM"; 413 break; 414 case SMB2_ENCRYPTION_AES128_GCM: 415 encryption = "AES-128-GCM"; 416 break; 417 default: 418 encryption = "???"; 419 result = -1; 420 break; 421 } 422 } else if (smbXsrv_is_partially_encrypted(session->encryption_flags)) { 423 switch (session->cipher) { 424 case SMB_ENCRYPTION_GSSAPI: 425 encryption = "partial(GSSAPI)"; 426 break; 427 case SMB2_ENCRYPTION_AES128_CCM: 428 encryption = "partial(AES-128-CCM)"; 429 break; 430 case SMB2_ENCRYPTION_AES128_GCM: 431 encryption = "partial(AES-128-GCM)"; 432 break; 433 default: 434 encryption = "???"; 435 result = -1; 436 break; 437 } 438 } 439 440 if (smbXsrv_is_signed(session->signing_flags)) { 441 if (session->connection_dialect >= SMB3_DIALECT_REVISION_302) { 442 signing = "AES-128-CMAC"; 443 } else if (session->connection_dialect >= SMB2_DIALECT_REVISION_202) { 444 signing = "HMAC-SHA256"; 445 } else { 446 signing = "HMAC-MD5"; 447 } 448 } else if (smbXsrv_is_partially_signed(session->signing_flags)) { 449 if (session->connection_dialect >= SMB3_DIALECT_REVISION_302) { 450 signing = "partial(AES-128-CMAC)"; 451 } else if (session->connection_dialect >= SMB2_DIALECT_REVISION_202) { 452 signing = "partial(HMAC-SHA256)"; 453 } else { 454 signing = "partial(HMAC-MD5)"; 455 } 456 } 457 458 459 d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n", 460 server_id_str_buf(session->pid, &tmp), 461 uid_str, gid_str, 462 machine_hostname, 463 session_dialect_str(session->connection_dialect), 464 encryption, 465 signing); 466 467 TALLOC_FREE(machine_hostname); 468 469 return result; 470 } 471 472 473 static bool print_notify_rec(const char *path, struct server_id server, 474 const struct notify_instance *instance, 475 void *private_data) 476 { 477 struct server_id_buf idbuf; 478 479 d_printf("%s\\%s\\%x\\%x\n", path, server_id_str_buf(server, &idbuf), 480 (unsigned)instance->filter, 481 (unsigned)instance->subdir_filter); 482 483 return true; 484 } 485 486 int main(int argc, const char *argv[]) 290 487 { 291 488 int c; 292 489 int profile_only = 0; 293 490 bool show_processes, show_locks, show_shares; 491 bool show_notify = false; 294 492 poptContext pc; 295 493 struct poptOption long_options[] = { … … 299 497 {"locks", 'L', POPT_ARG_NONE, NULL, 'L', "Show locks only" }, 300 498 {"shares", 'S', POPT_ARG_NONE, NULL, 'S', "Show shares only" }, 499 {"notify", 'N', POPT_ARG_NONE, NULL, 'N', "Show notifies" }, 301 500 {"user", 'u', POPT_ARG_STRING, &username, 'u', "Switch to user" }, 302 501 {"brief", 'b', POPT_ARG_NONE, NULL, 'b', "Be brief" }, … … 305 504 {"byterange", 'B', POPT_ARG_NONE, NULL, 'B', "Include byte range locks"}, 306 505 {"numeric", 'n', POPT_ARG_NONE, NULL, 'n', "Numeric uid/gid"}, 506 {"fast", 'f', POPT_ARG_NONE, NULL, 'f', "Skip checks if processes still exist"}, 307 507 POPT_COMMON_SAMBA 308 508 POPT_TABLEEND … … 310 510 TALLOC_CTX *frame = talloc_stackframe(); 311 511 int ret = 0; 312 struct messaging_context *msg_ctx; 512 struct messaging_context *msg_ctx = NULL; 513 char *db_path; 514 bool ok; 313 515 314 516 sec_init(); 315 load_case_tables();517 smb_init_locale(); 316 518 317 519 setup_logging(argv[0], DEBUG_STDERR); 520 lp_set_cmdline("log level", "0"); 318 521 319 522 if (getuid() != geteuid()) { … … 323 526 } 324 527 325 pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 528 if (getuid() != 0) { 529 d_printf("smbstatus only works as root!\n"); 530 ret = 1; 531 goto done; 532 } 533 534 535 pc = poptGetContext(NULL, argc, argv, long_options, 326 536 POPT_CONTEXT_KEEP_FIRST); 327 537 … … 340 550 shares_only = true; 341 551 break; 552 case 'N': 553 show_notify = true; 554 break; 342 555 case 'b': 343 556 brief = true; … … 355 568 case 'n': 356 569 numeric_only = true; 570 break; 571 case 'f': 572 do_checks = false; 357 573 break; 358 574 } … … 380 596 381 597 382 if (!sessionid_init_readonly()) { 383 fprintf(stderr, "Can't open sessionid.tdb\n"); 598 /* 599 * This implicitly initializes the global ctdbd connection, 600 * usable by the db_open() calls further down. 601 */ 602 msg_ctx = messaging_init(NULL, samba_tevent_context_init(NULL)); 603 if (msg_ctx == NULL) { 604 fprintf(stderr, "messaging_init failed\n"); 384 605 ret = -1; 385 606 goto done; 386 607 } 387 608 388 if (lp_clustering()) { 389 /* 390 * This implicitly initializes the global ctdbd 391 * connection, usable by the db_open() calls further 392 * down. 393 */ 394 msg_ctx = messaging_init(NULL, procid_self(), 395 event_context_init(NULL)); 396 if (msg_ctx == NULL) { 397 fprintf(stderr, "messaging_init failed\n"); 398 ret = -1; 399 goto done; 400 } 401 } 402 403 if (!lp_load(get_dyn_CONFIGFILE(),False,False,False,True)) { 609 if (!lp_load_global(get_dyn_CONFIGFILE())) { 404 610 fprintf(stderr, "Can't load %s - run testparm to debug it\n", 405 611 get_dyn_CONFIGFILE()); … … 411 617 case 'P': 412 618 /* Dump profile data */ 413 return status_profile_dump(verbose); 619 ok = status_profile_dump(verbose); 620 return ok ? 0 : 1; 414 621 case 'R': 415 622 /* Continuously display rate-converted data */ 416 return status_profile_rates(verbose); 623 ok = status_profile_rates(verbose); 624 return ok ? 0 : 1; 417 625 default: 418 626 break; … … 421 629 if ( show_processes ) { 422 630 d_printf("\nSamba version %s\n",samba_version_string()); 423 d_printf("PID Username Group Machine \n"); 424 d_printf("-------------------------------------------------------------------\n"); 425 if (lp_security() == SEC_SHARE) { 426 d_printf(" <processes do not show up in " 427 "anonymous mode>\n"); 428 } 429 430 sessionid_traverse_read(traverse_sessionid, NULL); 631 d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n", "PID", "Username", "Group", "Machine", "Protocol Version", "Encryption", "Signing"); 632 d_printf("----------------------------------------------------------------------------------------------------------------------------------------\n"); 633 634 sessionid_traverse_read(traverse_sessionid, frame); 431 635 432 636 if (processes_only) { … … 436 640 437 641 if ( show_shares ) { 438 if (verbose) {439 d_printf("Opened %s\n", lock_path("connections.tdb"));440 }441 442 642 if (brief) { 443 643 goto done; 444 644 } 445 645 446 d_printf("\n Service pid machine Connected at\n");447 d_printf("------------------------------------------------------- \n");448 449 connections_forall_read(traverse_ fn1, NULL);646 d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing"); 647 d_printf("---------------------------------------------------------------------------------------------\n"); 648 649 connections_forall_read(traverse_connections, frame); 450 650 451 651 d_printf("\n"); … … 459 659 int result; 460 660 struct db_context *db; 461 db = db_open(NULL, lock_path("locking.tdb"), 0, 462 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0); 661 662 db_path = lock_path("locking.tdb"); 663 if (db_path == NULL) { 664 d_printf("Out of memory - exiting\n"); 665 ret = -1; 666 goto done; 667 } 668 669 db = db_open(NULL, db_path, 0, 670 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0, 671 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE); 463 672 464 673 if (!db) { 465 d_printf("%s not initialised\n", 466 lock_path("locking.tdb")); 674 d_printf("%s not initialised\n", db_path); 467 675 d_printf("This is normal if an SMB client has never " 468 676 "connected to your server.\n"); 677 TALLOC_FREE(db_path); 469 678 exit(0); 470 679 } else { 471 680 TALLOC_FREE(db); 681 TALLOC_FREE(db_path); 472 682 } 473 683 … … 478 688 } 479 689 480 if (!serverid_init_readonly(frame)) { 481 d_printf("Can't initialise serverid tdb - exiting\n"); 482 ret = 1; 483 goto done; 484 } 485 result = share_mode_forall(print_share_mode, NULL); 690 result = share_entry_forall(print_share_mode, NULL); 486 691 487 692 if (result == 0) { 488 693 d_printf("No locked files\n"); 489 } else if (result == -1) {694 } else if (result < 0) { 490 695 d_printf("locked file list truncated\n"); 491 696 } … … 498 703 499 704 locking_end(); 705 } 706 707 if (show_notify) { 708 struct notify_context *n; 709 710 n = notify_init(talloc_tos(), msg_ctx, 711 messaging_tevent_context(msg_ctx)); 712 if (n == NULL) { 713 goto done; 714 } 715 notify_walk(n, print_notify_rec, NULL); 716 TALLOC_FREE(n); 500 717 } 501 718
Note:
See TracChangeset
for help on using the changeset viewer.