Ignore:
Timestamp:
Sep 30, 2007, 3:42:50 AM (18 years ago)
Author:
Paul Smedley
Message:

Update trunk to 3.2.0pre1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/samba/source/utils/status.c

    r30 r77  
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2 of the License, or
     8   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    1010   
     
    1515   
    1616   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/>.
    1918
    2019   Revision History:
     
    3635#define SMB_MAXPIDS             2048
    3736static uid_t            Ucrit_uid = 0;               /* added by OH */
    38 static pid_t            Ucrit_pid[SMB_MAXPIDS];  /* Ugly !!! */   /* added by OH */
     37static struct server_id Ucrit_pid[SMB_MAXPIDS];  /* Ugly !!! */   /* added by OH */
    3938static int              Ucrit_MaxPid=0;                    /* added by OH */
    4039static unsigned int     Ucrit_IsActive = 0;                /* added by OH */
     
    7069}
    7170
    72 static unsigned int Ucrit_checkPid(pid_t pid)
     71static unsigned int Ucrit_checkPid(struct server_id pid)
    7372{
    7473        int i;
     
    7877       
    7978        for (i=0;i<Ucrit_MaxPid;i++) {
    80                 if( pid == Ucrit_pid[i] )
     79                if (cluster_id_equal(&pid, &Ucrit_pid[i]))
    8180                        return 1;
    8281        }
     
    8584}
    8685
    87 static BOOL Ucrit_addPid( pid_t pid )
     86static BOOL Ucrit_addPid( struct server_id pid )
    8887{
    8988        if ( !Ucrit_IsActive )
     
    113112        }
    114113
     114        if (!process_exists(e->pid)) {
     115                return;
     116        }
     117
    115118        if (count==0) {
    116119                d_printf("Locked files:\n");
     
    120123        count++;
    121124
    122         if (Ucrit_checkPid(procid_to_pid(&e->pid))) {
     125        if (Ucrit_checkPid(e->pid)) {
    123126                d_printf("%-11s  ",procid_str_static(&e->pid));
    124127                d_printf("%-9u  ", (unsigned int)e->uid);
     
    167170}
    168171
    169 static void print_brl(SMB_DEV_T dev,
    170                         SMB_INO_T ino,
    171                         struct process_id pid,
     172static void print_brl(struct file_id id,
     173                        struct server_id pid,
    172174                        enum brl_type lock_type,
    173175                        enum brl_flavour lock_flav,
    174176                        br_off start,
    175                         br_off size)
     177                        br_off size,
     178                        void *private_data)
    176179{
    177180        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
    178197        if (count==0) {
    179198                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");
    182201        }
    183202        count++;
    184203
    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
     225static 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)
    196231                return 0;
    197232
    198         memcpy(&crec, dbuf.dptr, sizeof(crec));
    199 
    200         if (crec.cnum == -1)
     233        if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) {
    201234                return 0;
    202 
    203         if (!process_exists(crec.pid) || !Ucrit_checkUid(crec.uid)) {
    204                 return 0;
    205235        }
    206236
    207237        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));
    211241
    212242        return 0;
    213243}
    214244
    215 static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
     245static int traverse_sessionid(struct db_record *db, void *state)
    216246{
    217247        struct sessionid sessionid;
    218248        fstring uid_str, gid_str;
    219249
    220         if (dbuf.dsize != sizeof(sessionid))
     250        if (db->value.dsize != sizeof(sessionid))
    221251                return 0;
    222252
    223         memcpy(&sessionid, dbuf.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)) {
    226256                return 0;
    227257        }
     
    232262        fstr_sprintf(gid_str, "%d", sessionid.gid);
    233263
    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),
    236266                 numeric_only ? uid_str : uidtoname(sessionid.uid),
    237267                 numeric_only ? gid_str : gidtoname(sessionid.gid),
     
    248278        int c;
    249279        int profile_only = 0;
    250         TDB_CONTEXT *tdb;
    251280        BOOL show_processes, show_locks, show_shares;
    252281        poptContext pc;
     
    266295                POPT_TABLEEND
    267296        };
     297        TALLOC_CTX *frame = talloc_stackframe();
     298        int ret = 0;
    268299
    269300        sec_init();
     
    276307        if (getuid() != geteuid()) {
    277308                d_printf("smbstatus should not be run setuid\n");
    278                 return(1);
     309                ret = 1;
     310                goto done;
    279311        }
    280312
     
    308340        if (!lp_load(dyn_CONFIGFILE,False,False,False,True)) {
    309341                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       
    313353        switch (profile_only) {
    314354                case 'P':
     
    323363
    324364        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) {
    327369                        d_printf("sessionid.tdb not initialised\n");
    328370                } else {
     
    331373                        d_printf("-------------------------------------------------------------------\n");
    332374
    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                }
    339382        }
    340383 
    341384        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                }
    353392               
    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                }
    365403        }
    366404
    367405        if ( show_locks ) {
    368                 int ret;
     406                int result;
    369407
    370408                if (!locking_init(1)) {
    371409                        d_printf("Can't initialise locking module - exiting\n");
    372                         exit(1);
     410                        ret = 1;
     411                        goto done;
    373412                }
    374413               
    375                 ret = share_mode_forall(print_share_mode, NULL);
    376 
    377                 if (ret == 0) {
     414                result = share_mode_forall(print_share_mode, NULL);
     415
     416                if (result == 0) {
    378417                        d_printf("No locked files\n");
    379                 } else if (ret == -1) {
     418                } else if (result == -1) {
    380419                        d_printf("locked file list truncated\n");
    381420                }
     
    384423
    385424                if (show_brl) {
    386                         brl_forall(print_brl);
     425                        brl_forall(print_brl, NULL);
    387426                }
    388427               
     
    390429        }
    391430
    392         return (0);
    393 }
     431done:
     432        TALLOC_FREE(frame);
     433        return ret;
     434}
Note: See TracChangeset for help on using the changeset viewer.