Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/utils/status.c

    r860 r988  
    3232
    3333#include "includes.h"
     34#include "smbd/globals.h"
    3435#include "system/filesys.h"
    3536#include "popt_common.h"
    36 #include "dbwrap.h"
     37#include "dbwrap/dbwrap.h"
     38#include "dbwrap/dbwrap_open.h"
    3739#include "../libcli/security/security.h"
    3840#include "session.h"
    3941#include "locking/proto.h"
    4042#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"
    4147#include "serverid.h"
     48#include "status_profile.h"
     49#include "smbd/notifyd/notifyd.h"
    4250
    4351#define SMB_MAXPIDS             2048
     
    5361static bool show_brl;
    5462static bool numeric_only;
     63static bool do_checks = true;
    5564
    5665const char *username = NULL;
    57 
    58 extern bool status_profile_dump(bool be_verbose);
    59 extern bool status_profile_rates(bool be_verbose);
    6066
    6167/* added by OH */
     
    8591
    8692        for (i=0;i<Ucrit_MaxPid;i++) {
    87                 if (cluster_id_equal(&pid, &Ucrit_pid[i]))
     93                if (serverid_equal(&pid, &Ucrit_pid[i])) {
    8894                        return 1;
     95                }
    8996        }
    9097
     
    109116}
    110117
    111 static void print_share_mode(const struct share_mode_entry *e,
    112                              const char *sharepath,
    113                              const char *fname,
    114                              void *dummy)
     118static 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)
    115123{
    116124        static int count;
    117125
    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;
    124128        }
    125129
     
    131135        count++;
    132136
     137        if (do_checks && !serverid_exists(&e->pid)) {
     138                /* the process for this entry does not exist any more */
     139                return 0;
     140        }
     141
    133142        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));
    135145                d_printf("%-9u  ", (unsigned int)e->uid);
    136146                switch (map_share_mode_to_deny_mode(e->share_access,
     
    170180                } else if (e->op_type & LEVEL_II_OPLOCK) {
    171181                        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)?"":" ");
    172191                } else {
    173192                        d_printf("NONE            ");
    174193                }
    175194
    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;
    178202}
    179203
     
    187211{
    188212        static int count;
    189         int i;
     213        unsigned int i;
    190214        static const struct {
    191215                enum brl_type lock_type;
     
    202226        char *fname = NULL;
    203227        struct share_mode_lock *share_mode;
     228        struct server_id_buf tmp;
    204229
    205230        if (count==0) {
     
    212237        share_mode = fetch_share_mode_unlocked(NULL, id);
    213238        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,
    217243                                        has_stream ? ":" : "",
    218                                         has_stream ? share_mode->stream_name :
     244                                        has_stream ?
     245                                        share_mode->data->stream_name :
    219246                                        "");
    220247        } else {
     
    231258        }
    232259
    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),
    235262                 desc,
    236                  (double)start, (double)size,
     263                 (intmax_t)start, (intmax_t)size,
    237264                 sharepath, fname);
    238265
     
    241268}
    242269
    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)
     270static 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
     299static 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)
    248311                return 0;
    249312
    250         if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) {
     313        if (do_checks &&
     314            (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid))) {
    251315                return 0;
    252316        }
    253317
    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),
    256353                 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;
    260361}
    261362
     
    263364                              void *private_data)
    264365{
     366        TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data;
    265367        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))) {
    269377                return 0;
    270378        }
     
    272380        Ucrit_addPid(session->pid);
    273381
    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
     473static 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
     486int main(int argc, const char *argv[])
    290487{
    291488        int c;
    292489        int profile_only = 0;
    293490        bool show_processes, show_locks, show_shares;
     491        bool show_notify = false;
    294492        poptContext pc;
    295493        struct poptOption long_options[] = {
     
    299497                {"locks",       'L', POPT_ARG_NONE,     NULL, 'L', "Show locks only" },
    300498                {"shares",      'S', POPT_ARG_NONE,     NULL, 'S', "Show shares only" },
     499                {"notify",      'N', POPT_ARG_NONE,     NULL, 'N', "Show notifies" },
    301500                {"user",        'u', POPT_ARG_STRING,   &username, 'u', "Switch to user" },
    302501                {"brief",       'b', POPT_ARG_NONE,     NULL, 'b', "Be brief" },
     
    305504                {"byterange",   'B', POPT_ARG_NONE,     NULL, 'B', "Include byte range locks"},
    306505                {"numeric",     'n', POPT_ARG_NONE,     NULL, 'n', "Numeric uid/gid"},
     506                {"fast",        'f', POPT_ARG_NONE,     NULL, 'f', "Skip checks if processes still exist"},
    307507                POPT_COMMON_SAMBA
    308508                POPT_TABLEEND
     
    310510        TALLOC_CTX *frame = talloc_stackframe();
    311511        int ret = 0;
    312         struct messaging_context *msg_ctx;
     512        struct messaging_context *msg_ctx = NULL;
     513        char *db_path;
     514        bool ok;
    313515
    314516        sec_init();
    315         load_case_tables();
     517        smb_init_locale();
    316518
    317519        setup_logging(argv[0], DEBUG_STDERR);
     520        lp_set_cmdline("log level", "0");
    318521
    319522        if (getuid() != geteuid()) {
     
    323526        }
    324527
    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,
    326536                            POPT_CONTEXT_KEEP_FIRST);
    327537
     
    340550                        shares_only = true;
    341551                        break;
     552                case 'N':
     553                        show_notify = true;
     554                        break;
    342555                case 'b':
    343556                        brief = true;
     
    355568                case 'n':
    356569                        numeric_only = true;
     570                        break;
     571                case 'f':
     572                        do_checks = false;
    357573                        break;
    358574                }
     
    380596
    381597
    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");
    384605                ret = -1;
    385606                goto done;
    386607        }
    387608
    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())) {
    404610                fprintf(stderr, "Can't load %s - run testparm to debug it\n",
    405611                        get_dyn_CONFIGFILE());
     
    411617                case 'P':
    412618                        /* Dump profile data */
    413                         return status_profile_dump(verbose);
     619                        ok = status_profile_dump(verbose);
     620                        return ok ? 0 : 1;
    414621                case 'R':
    415622                        /* Continuously display rate-converted data */
    416                         return status_profile_rates(verbose);
     623                        ok = status_profile_rates(verbose);
     624                        return ok ? 0 : 1;
    417625                default:
    418626                        break;
     
    421629        if ( show_processes ) {
    422630                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);
    431635
    432636                if (processes_only) {
     
    436640
    437641        if ( show_shares ) {
    438                 if (verbose) {
    439                         d_printf("Opened %s\n", lock_path("connections.tdb"));
    440                 }
    441 
    442642                if (brief) {
    443643                        goto done;
    444644                }
    445645
    446                 d_printf("\nService      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);
    450650
    451651                d_printf("\n");
     
    459659                int result;
    460660                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);
    463672
    464673                if (!db) {
    465                         d_printf("%s not initialised\n",
    466                                  lock_path("locking.tdb"));
     674                        d_printf("%s not initialised\n", db_path);
    467675                        d_printf("This is normal if an SMB client has never "
    468676                                 "connected to your server.\n");
     677                        TALLOC_FREE(db_path);
    469678                        exit(0);
    470679                } else {
    471680                        TALLOC_FREE(db);
     681                        TALLOC_FREE(db_path);
    472682                }
    473683
     
    478688                }
    479689
    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);
    486691
    487692                if (result == 0) {
    488693                        d_printf("No locked files\n");
    489                 } else if (result == -1) {
     694                } else if (result < 0) {
    490695                        d_printf("locked file list truncated\n");
    491696                }
     
    498703
    499704                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);
    500717        }
    501718
Note: See TracChangeset for help on using the changeset viewer.