bool leases_db_init(bool read_only)
{
	if (leases_db) {
		return true;
	}

	leases_db = db_open(NULL, lock_path("leases.tdb"), 0,
			    TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|
			    TDB_INCOMPATIBLE_HASH,
			    read_only ? O_RDONLY : O_RDWR|O_CREAT, 0644,
			    DBWRAP_LOCK_ORDER_2, DBWRAP_FLAG_NONE);

	if (leases_db == NULL) {
		DEBUG(1, ("ERROR: Failed to initialise leases database\n"));
		return false;
	}

	return true;
}
示例#2
0
/****************************************************************************
check for a particular packet in the unexpected packet queue
  **************************************************************************/
struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, 
					 const char *mailslot_name)
{
	TDB_CONTEXT *tdb2;

	tdb2 = tdb_open_log(lock_path("unexpected.tdb"), 0, 0, O_RDONLY, 0);
	if (!tdb2) return NULL;

	matched_packet = NULL;
	match_id = id;
	match_type = packet_type;
	match_name = mailslot_name;

	tdb_traverse(tdb2, traverse_match, NULL);

	tdb_close(tdb2);

	return matched_packet;
}
示例#3
0
/****************************************************************************
Send a message to smbd to do a sam synchronisation
**************************************************************************/
static void send_sync_message(void)
{
        TDB_CONTEXT *tdb;

        tdb = tdb_open_log(lock_path("connections.tdb"), 0,
                           TDB_DEFAULT, O_RDONLY, 0);

        if (!tdb) {
                DEBUG(3, ("send_sync_message(): failed to open connections "
                          "database\n"));
                return;
        }

        DEBUG(3, ("sending sam synchronisation message\n"));
        
        message_send_all(tdb, MSG_SMB_SAM_SYNC, NULL, 0, False, NULL);

        tdb_close(tdb);
}
示例#4
0
/*
  Open up the notify.tdb database. You should close it down using
  talloc_free(). We need the messaging_ctx to allow for notifications
  via internal messages
*/
struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, 
				   struct messaging_context *messaging_ctx,
				   struct event_context *ev,
				   connection_struct *conn)
{
	struct notify_context *notify;

	if (!lp_change_notify(conn->params)) {
		return NULL;
	}

	notify = talloc(mem_ctx, struct notify_context);
	if (notify == NULL) {
		return NULL;
	}

	notify->db = db_open(notify, lock_path("notify.tdb"),
				  0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
				  O_RDWR|O_CREAT, 0644);
	if (notify->db == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->server = server;
	notify->messaging_ctx = messaging_ctx;
	notify->list = NULL;
	notify->array = NULL;
	notify->seqnum = notify->db->get_seqnum(notify->db);
	notify->key = string_term_tdb_data(NOTIFY_KEY);

	talloc_set_destructor(notify, notify_destructor);

	/* register with the messaging subsystem for the notify
	   message type */
	messaging_register(notify->messaging_ctx, notify, 
			   MSG_PVFS_NOTIFY, notify_handler);

	notify->sys_notify_ctx = sys_notify_context_create(conn, notify, ev);

	return notify;
}
示例#5
0
文件: brlock.c 项目: jophxy/samba
void brl_init(int read_only)
{
	if (tdb)
		return;
	tdb = tdb_open_log(lock_path("brlock.tdb"), 0,  TDB_DEFAULT|(read_only?0x0:TDB_CLEAR_IF_FIRST),
		       read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644);
	if (!tdb) {
		DEBUG(0,("Failed to open byte range locking database\n"));
		return;
	}

#if DONT_DO_THIS
	/* doing this traversal could kill solaris machines under high load (tridge) */
	/* delete any dead locks */
	if (!read_only) {
		BOOL check_self = False;
		tdb_traverse(tdb, delete_fn, &check_self);
	}
#endif
}
示例#6
0
BOOL message_init(void)
{
	if (tdb) return True;

	tdb = tdb_open_log(lock_path("messages.tdb"),
		       0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
		       O_RDWR|O_CREAT,0600);

	if (!tdb) {
		DEBUG(0,("ERROR: Failed to initialise messages database\n"));
		return False;
	}

	CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1);

	message_register(MSG_PING, ping_message);
	message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message);

	return True;
}
示例#7
0
文件: serverid.c 项目: Gazzonyx/samba
static struct db_context *serverid_db(void)
{
	static struct db_context *db;
	char *db_path;

	if (db != NULL) {
		return db;
	}

	db_path = lock_path("serverid.tdb");
	if (db_path == NULL) {
		return NULL;
	}

	db = db_open(NULL, db_path, 0,
		     TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
		     O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_2,
		     DBWRAP_FLAG_NONE);
	TALLOC_FREE(db_path);
	return db;
}
示例#8
0
static void send_repl_message(uint32 low_serial)
{
        TDB_CONTEXT *tdb;

        tdb = tdb_open_log(lock_path("connections.tdb"), 0,
                           TDB_DEFAULT, O_RDONLY, 0);

        if (!tdb) {
                DEBUG(3, ("send_repl_message(): failed to open connections "
                          "database\n"));
                return;
        }

        DEBUG(3, ("sending replication message, serial = 0x%04x\n", 
                  low_serial));
        
        message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial,
                         sizeof(low_serial), False, NULL);

        tdb_close(tdb);
}
示例#9
0
/* flush the cache */
void wcache_flush_cache(void)
{
	extern BOOL opt_nocache;

	if (!wcache)
		return;
	if (wcache->tdb) {
		tdb_close(wcache->tdb);
		wcache->tdb = NULL;
	}
	if (opt_nocache)
		return;

	wcache->tdb = tdb_open_log(lock_path("winbindd_cache.tdb"), 5000, 
				   TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0600);

	if (!wcache->tdb) {
		DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
	}
	DEBUG(10,("wcache_flush_cache success\n"));
}
示例#10
0
/****************************************************************************
 Initialise the locking functions.
****************************************************************************/
BOOL locking_init(int read_only)
{
	brl_init(read_only);

	if (tdb)
		return True;

	tdb = tdb_open(lock_path("locking.tdb"),
		       0, TDB_CLEAR_IF_FIRST,
		       read_only ? O_RDONLY : O_RDWR | O_CREAT, 0644);

	if (!tdb)
	{
		DEBUG(0, ("ERROR: Failed to initialise share modes\n"));
		return False;
	}

	if (!posix_locking_init(read_only))
		return False;

	return True;
}
示例#11
0
NTSTATUS smbXsrv_session_global_init(void)
{
	char *global_path = NULL;
	struct db_context *db_ctx = NULL;

	if (smbXsrv_session_global_db_ctx != NULL) {
		return NT_STATUS_OK;
	}

	/*
	 * This contains secret information like session keys!
	 */
	global_path = lock_path("smbXsrv_session_global.tdb");
	if (global_path == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	db_ctx = db_open(NULL, global_path,
			 0, /* hash_size */
			 TDB_DEFAULT |
			 TDB_CLEAR_IF_FIRST |
			 TDB_INCOMPATIBLE_HASH,
			 O_RDWR | O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1,
			 DBWRAP_FLAG_NONE);
	TALLOC_FREE(global_path);
	if (db_ctx == NULL) {
		NTSTATUS status;

		status = map_nt_error_from_unix_common(errno);

		return status;
	}

	smbXsrv_session_global_db_ctx = db_ctx;

	return NT_STATUS_OK;
}
示例#12
0
static bool locking_init_internal(bool read_only)
{
	brl_init(read_only);

	if (lock_db)
		return True;

	lock_db = db_open(NULL, lock_path("locking.tdb"),
			  lp_open_files_db_hash_size(),
			  TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
			  read_only?O_RDONLY:O_RDWR|O_CREAT, 0644,
			  DBWRAP_LOCK_ORDER_1);

	if (!lock_db) {
		DEBUG(0,("ERROR: Failed to initialise locking database\n"));
		return False;
	}

	if (!posix_locking_init(read_only))
		return False;

	return True;
}
示例#13
0
struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
                                     int timeout)
{
    struct named_mutex *result;

    result = talloc(mem_ctx, struct named_mutex);
    if (result == NULL) {
        DEBUG(0, ("talloc failed\n"));
        return NULL;
    }

    result->name = talloc_strdup(result, name);
    if (result->name == NULL) {
        DEBUG(0, ("talloc failed\n"));
        TALLOC_FREE(result);
        return NULL;
    }

    result->tdb = tdb_wrap_open(result, lock_path("mutex.tdb"), 0,
                                TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
    if (result->tdb == NULL) {
        DEBUG(1, ("Could not open mutex.tdb: %s\n",
                  strerror(errno)));
        TALLOC_FREE(result);
        return NULL;
    }

    if (tdb_lock_bystring_with_timeout(result->tdb->tdb, name,
                                       timeout) == -1) {
        DEBUG(1, ("Could not get the lock for %s\n", name));
        TALLOC_FREE(result);
        return NULL;
    }

    talloc_set_destructor(result, unlock_named_mutex);
    return result;
}
示例#14
0
BOOL locking_init(int read_only)
{
	brl_init(read_only);

	if (tdb)
		return True;

	tdb = tdb_open_log(lock_path("locking.tdb"),
		       0, TDB_DEFAULT|(read_only?0x0:TDB_CLEAR_IF_FIRST),
		       read_only?O_RDONLY:O_RDWR|O_CREAT,
		       0644);

	if (!tdb) {
		DEBUG(0,("ERROR: Failed to initialise locking database\n"));
		return False;
	}

	if (!posix_locking_init(read_only))
		return False;

	open_read_only = read_only;

	return True;
}
示例#15
0
BOOL init_account_policy(void)
{
	static pid_t local_pid;
	const char *vstring = "INFO/version";
	uint32 version;

	if (tdb && local_pid == sys_getpid())
		return True;
	tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
	if (!tdb) {
		DEBUG(0,("Failed to open account policy database\n"));
		return False;
	}

	local_pid = sys_getpid();

	/* handle a Samba upgrade */
	tdb_lock_bystring(tdb, vstring,0);
	if (!tdb_fetch_uint32(tdb, vstring, &version) || version != DATABASE_VERSION) {
		tdb_traverse(tdb, tdb_traverse_delete_fn, NULL);
		tdb_store_uint32(tdb, vstring, DATABASE_VERSION);
		
		account_policy_set(AP_MIN_PASSWORD_LEN, MINPASSWDLENGTH);   /* 5 chars minimum             */
		account_policy_set(AP_PASSWORD_HISTORY, 0);		    /* don't keep any old password */
		account_policy_set(AP_USER_MUST_LOGON_TO_CHG_PASS, 0);	    /* don't force user to logon   */
		account_policy_set(AP_MAX_PASSWORD_AGE, (uint32)-1);        /* don't expire		   */
		account_policy_set(AP_MIN_PASSWORD_AGE, 0);		    /* 0 days                      */
		account_policy_set(AP_LOCK_ACCOUNT_DURATION, 30);	    /* lockout for 30 minutes      */
		account_policy_set(AP_RESET_COUNT_TIME, 30);		    /* reset after 30 minutes      */
		account_policy_set(AP_BAD_ATTEMPT_LOCKOUT, 0);		    /* don't lockout               */
		account_policy_set(AP_TIME_TO_LOGOUT, -1);		    /* don't force logout          */
	}
	tdb_unlock_bystring(tdb, vstring);

	return True;
}
示例#16
0
BOOL message_init(void)
{
	if (tdb) return True;

	tdb = tdb_open_log(lock_path("messages.tdb"), 
		       0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 
		       O_RDWR|O_CREAT,0600);

	if (!tdb) {
		DEBUG(0,("ERROR: Failed to initialise messages database\n"));
		return False;
	}

	CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1);

	message_register(MSG_PING, ping_message);

	/* Register some debugging related messages */

	register_msg_pool_usage();
	register_dmalloc_msgs();

	return True;
}
示例#17
0
NTSTATUS smbXsrv_version_global_init(const struct server_id *server_id)
{
    const char *global_path = NULL;
    struct db_context *db_ctx = NULL;
    struct db_record *db_rec = NULL;
    TDB_DATA key;
    TDB_DATA val;
    DATA_BLOB blob;
    struct smbXsrv_version_globalB global_blob;
    enum ndr_err_code ndr_err;
    struct smbXsrv_version_global0 *global = NULL;
    uint32_t i;
    uint32_t num_valid = 0;
    struct smbXsrv_version_node0 *valid = NULL;
    struct smbXsrv_version_node0 *local_node = NULL;
    bool exists;
    NTSTATUS status;
    const char *key_string = "smbXsrv_version_global";
    TALLOC_CTX *frame;

    if (smbXsrv_version_global_db_ctx != NULL) {
        return NT_STATUS_OK;
    }

    frame = talloc_stackframe();

    global_path = lock_path("smbXsrv_version_global.tdb");
    if (global_path == NULL) {
        TALLOC_FREE(frame);
        return NT_STATUS_NO_MEMORY;
    }

    db_ctx = db_open(NULL, global_path,
                     0, /* hash_size */
                     TDB_DEFAULT |
                     TDB_CLEAR_IF_FIRST |
                     TDB_INCOMPATIBLE_HASH,
                     O_RDWR | O_CREAT, 0600,
                     DBWRAP_LOCK_ORDER_1,
                     DBWRAP_FLAG_NONE);
    if (db_ctx == NULL) {
        status = map_nt_error_from_unix_common(errno);
        DEBUG(0,("smbXsrv_version_global_init: "
                 "failed to open[%s] - %s\n",
                 global_path, nt_errstr(status)));
        TALLOC_FREE(frame);
        return status;
    }

    key = string_term_tdb_data(key_string);

    db_rec = dbwrap_fetch_locked(db_ctx, db_ctx, key);
    if (db_rec == NULL) {
        status = NT_STATUS_INTERNAL_DB_ERROR;
        DEBUG(0,("smbXsrv_version_global_init: "
                 "dbwrap_fetch_locked(%s) - %s\n",
                 key_string, nt_errstr(status)));
        TALLOC_FREE(frame);
        return status;
    }

    val = dbwrap_record_get_value(db_rec);
    if (val.dsize == 0) {
        global = talloc_zero(frame, struct smbXsrv_version_global0);
        if (global == NULL) {
            DEBUG(0,("smbXsrv_version_global_init: "
                     "talloc_zero failed - %s\n", __location__));
            TALLOC_FREE(frame);
            return NT_STATUS_NO_MEMORY;
        }
        ZERO_STRUCT(global_blob);
        global_blob.version = SMBXSRV_VERSION_CURRENT;
        global_blob.info.info0 = global;
    } else {
示例#18
0
/* show the current server status */
void status_page(void)
{
	const char *v;
	int autorefresh=0;
	int refresh_interval=30;
	TDB_CONTEXT *tdb;

	smbd_pid = pidfile_pid("smbd");

	if (cgi_variable("smbd_restart")) {
		stop_smbd();
		start_smbd();
	}

	if (cgi_variable("smbd_start")) {
		start_smbd();
	}

	if (cgi_variable("smbd_stop")) {
		stop_smbd();
	}

	if (cgi_variable("nmbd_restart")) {
		stop_nmbd();
		start_nmbd();
	}
	if (cgi_variable("nmbd_start")) {
		start_nmbd();
	}

	if (cgi_variable("nmbd_stop")) {
		stop_nmbd();
	}

	if (cgi_variable("autorefresh")) {
		autorefresh = 1;
	} else if (cgi_variable("norefresh")) {
		autorefresh = 0;
	} else if (cgi_variable("refresh")) {
		autorefresh = 1;
	}

	if ((v=cgi_variable("refresh_interval"))) {
		refresh_interval = atoi(v);
	}

	if (cgi_variable("show_client_in_col_1")) {
		PID_or_Machine = 1;
	}

	tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
	if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);

	initPid2Machine ();

	printf("<H2>Server Status</H2>\n");

	printf("<FORM method=post>\n");

	if (!autorefresh) {
		printf("<input type=submit value=\"Auto Refresh\" name=autorefresh>\n");
		printf("<br>Refresh Interval: ");
		printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n", 
		       refresh_interval);
	} else {
		printf("<input type=submit value=\"Stop Refreshing\" name=norefresh>\n");
		printf("<br>Refresh Interval: %d\n", refresh_interval);
		printf("<input type=hidden name=refresh value=1>\n");
	}

	printf("<p>\n");

	if (!tdb) {
		/* open failure either means no connections have been
                   made or status=no */
		if (!lp_status(-1))
			printf("You need to have status=yes in your smb config file\n");
	}


	printf("<table>\n");

	printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);

	fflush(stdout);
	printf("<tr><td>smbd:</td><td>%srunning</td>\n",smbd_running()?"":"not ");
	if (geteuid() == 0) {
	    if (smbd_running()) {
		printf("<td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td>\n");
	    } else {
		printf("<td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td>\n");
	    }
	    printf("<td><input type=submit name=\"smbd_restart\" value=\"Restart smbd\"></td>\n");
	}
	printf("</tr>\n");

	fflush(stdout);
	printf("<tr><td>nmbd:</td><td>%srunning</td>\n",nmbd_running()?"":"not ");
	if (geteuid() == 0) {
	    if (nmbd_running()) {
		printf("<td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td>\n");
	    } else {
		printf("<td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td>\n");
	    }
	    printf("<td><input type=submit name=\"nmbd_restart\" value=\"Restart nmbd\"></td>\n");
	}
	printf("</tr>\n");

	printf("</table>\n");
	fflush(stdout);

	printf("<p><h3>Active Connections</h3>\n");
	printf("<table border=1>\n");
	printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th>\n");
	if (geteuid() == 0) {
		printf("<th>Kill</th>\n");
	}
	printf("</tr>\n");

	if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);

	printf("</table><p>\n");

	printf("<p><h3>Active Shares</h3>\n");
	printf("<table border=1>\n");
	printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");

	if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);

	printf("</table><p>\n");

	printf("<h3>Open Files</h3>\n");
	printf("<table border=1>\n");
	printf("<tr><th>%s</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n", PID_or_Machine ? "Client" : "PID");

	locking_init(1);
	share_mode_forall(print_share_mode);
	locking_end();
	printf("</table>\n");

	if (tdb) tdb_close(tdb);

	printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"Show Client in col 1\">\n");
	printf("<input type=submit name=\"show_pid_in_col_1\" value=\"Show PID in col 1\">\n");

	printf("</FORM>\n");

	if (autorefresh) {
		/* this little JavaScript allows for automatic refresh
                   of the page. There are other methods but this seems
                   to be the best alternative */
		printf("<script language=\"JavaScript\">\n");
		printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n", 
		       cgi_baseurl(),
		       refresh_interval,
		       refresh_interval*1000);
		printf("//-->\n</script>\n");
	}
}
示例#19
0
文件: status.c 项目: srimalik/samba
 int main(int argc, char *argv[])
{
	int c;
	int profile_only = 0;
	bool show_processes, show_locks, show_shares;
	poptContext pc;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"processes",	'p', POPT_ARG_NONE,	NULL, 'p', "Show processes only" },
		{"verbose",	'v', POPT_ARG_NONE, 	NULL, 'v', "Be verbose" },
		{"locks",	'L', POPT_ARG_NONE,	NULL, 'L', "Show locks only" },
		{"shares",	'S', POPT_ARG_NONE,	NULL, 'S', "Show shares only" },
		{"user", 	'u', POPT_ARG_STRING,	&username, 'u', "Switch to user" },
		{"brief",	'b', POPT_ARG_NONE, 	NULL, 'b', "Be brief" },
		{"profile",     'P', POPT_ARG_NONE, NULL, 'P', "Do profiling" },
		{"profile-rates", 'R', POPT_ARG_NONE, NULL, 'R', "Show call rates" },
		{"byterange",	'B', POPT_ARG_NONE,	NULL, 'B', "Include byte range locks"},
		{"numeric",	'n', POPT_ARG_NONE,	NULL, 'n', "Numeric uid/gid"},
		POPT_COMMON_SAMBA
		POPT_TABLEEND
	};
	TALLOC_CTX *frame = talloc_stackframe();
	int ret = 0;
	struct messaging_context *msg_ctx;

	sec_init();
	load_case_tables();

	setup_logging(argv[0], DEBUG_STDERR);

	if (getuid() != geteuid()) {
		d_printf("smbstatus should not be run setuid\n");
		ret = 1;
		goto done;
	}

	pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 
			    POPT_CONTEXT_KEEP_FIRST);

	while ((c = poptGetNextOpt(pc)) != -1) {
		switch (c) {
		case 'p':
			processes_only = true;
			break;
		case 'v':
			verbose = true;
			break;
		case 'L':
			locks_only = true;
			break;
		case 'S':
			shares_only = true;
			break;
		case 'b':
			brief = true;
			break;
		case 'u':
			Ucrit_addUid(nametouid(poptGetOptArg(pc)));
			break;
		case 'P':
		case 'R':
			profile_only = c;
			break;
		case 'B':
			show_brl = true;
			break;
		case 'n':
			numeric_only = true;
			break;
		}
	}

	/* setup the flags based on the possible combincations */

	show_processes = !(shares_only || locks_only || profile_only) || processes_only;
	show_locks     = !(shares_only || processes_only || profile_only) || locks_only;
	show_shares    = !(processes_only || locks_only || profile_only) || shares_only;

	if ( username )
		Ucrit_addUid( nametouid(username) );

	if (verbose) {
		d_printf("using configfile = %s\n", get_dyn_CONFIGFILE());
	}

	if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n",
			get_dyn_CONFIGFILE());
		ret = -1;
		goto done;
	}


	if (lp_clustering()) {
		/*
		 * This implicitly initializes the global ctdbd
		 * connection, usable by the db_open() calls further
		 * down.
		 */
		msg_ctx = messaging_init(NULL, event_context_init(NULL));
		if (msg_ctx == NULL) {
			fprintf(stderr, "messaging_init failed\n");
			ret = -1;
			goto done;
		}
	}

	if (!lp_load_global(get_dyn_CONFIGFILE())) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n",
			get_dyn_CONFIGFILE());
		ret = -1;
		goto done;
	}

	switch (profile_only) {
		case 'P':
			/* Dump profile data */
			return status_profile_dump(verbose);
		case 'R':
			/* Continuously display rate-converted data */
			return status_profile_rates(verbose);
		default:
			break;
	}

	if ( show_processes ) {
		d_printf("\nSamba version %s\n",samba_version_string());
		d_printf("PID     Username      Group         Machine                        \n");
		d_printf("-------------------------------------------------------------------\n");
		if (lp_security() == SEC_SHARE) {
			d_printf(" <processes do not show up in "
				 "anonymous mode>\n");
		}

		sessionid_traverse_read(traverse_sessionid, NULL);

		if (processes_only) {
			goto done;
		}
	}

	if ( show_shares ) {
		if (verbose) {
			d_printf("Opened %s\n", lock_path("connections.tdb"));
		}

		if (brief) {
			goto done;
		}

		d_printf("\nService      pid     machine       Connected at\n");
		d_printf("-------------------------------------------------------\n");

		connections_forall_read(traverse_fn1, NULL);

		d_printf("\n");

		if ( shares_only ) {
			goto done;
		}
	}

	if ( show_locks ) {
		int result;
		struct db_context *db;
		db = db_open(NULL, lock_path("locking.tdb"), 0,
			     TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
			     DBWRAP_LOCK_ORDER_1);

		if (!db) {
			d_printf("%s not initialised\n",
				 lock_path("locking.tdb"));
			d_printf("This is normal if an SMB client has never "
				 "connected to your server.\n");
			exit(0);
		} else {
			TALLOC_FREE(db);
		}

		if (!locking_init_readonly()) {
			d_printf("Can't initialise locking module - exiting\n");
			ret = 1;
			goto done;
		}

		result = share_mode_forall(print_share_mode, NULL);

		if (result == 0) {
			d_printf("No locked files\n");
		} else if (result < 0) {
			d_printf("locked file list truncated\n");
		}

		d_printf("\n");

		if (show_brl) {
			brl_forall(print_brl, NULL);
		}

		locking_end();
	}

done:
	TALLOC_FREE(frame);
	return ret;
}
示例#20
0
文件: lang_tdb.c 项目: hajuuk/R7000
/* initialise the message translation subsystem. If the "lang" argument
   is NULL then get the language from the normal environment variables */
BOOL lang_tdb_init(const char *lang)
{
	char *path = NULL;
	char *msg_path = NULL;
	struct stat st;
	static int initialised;
	time_t loadtime;
	BOOL result = False;

	/* we only want to init once per process, unless given
	   an override */
	if (initialised && !lang) 
		return True;

	if (initialised) {
		/* we are re-initialising, free up any old init */
		if (tdb) {
			tdb_close(tdb);
			tdb = NULL;
		}
		SAFE_FREE(current_lang);
	}

	initialised = 1;

	if (!lang) {
		/* no lang given, use environment */
		lang = get_lang();
	}

	/* if no lang then we don't translate */
	if (!lang) 
		return True;

	asprintf(&msg_path, "%s.msg", lib_path((const char *)lang));
	if (stat(msg_path, &st) != 0) {
		/* the msg file isn't available */
		DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, 
			   strerror(errno)));
		goto done;
	}
	
	asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang);

	DEBUG(10, ("lang_tdb_init: loading %s\n", path));

	tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
	if (!tdb) {
		tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDONLY, 0);
		if (!tdb) {
			DEBUG(10, ("lang_tdb_init: %s: %s\n", path,
				   strerror(errno)));
			goto done;
		}
		current_lang = SMB_STRDUP(lang);
		result = True;
		goto done;
	}

	loadtime = tdb_fetch_int32(tdb, "/LOADTIME/");

	if (loadtime == -1 || loadtime < st.st_mtime) {
		load_msg(msg_path);
		tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL));
	}

	current_lang = SMB_STRDUP(lang);
	result = True;

 done:
	SAFE_FREE(msg_path);
	SAFE_FREE(path);

	return result;
}
示例#21
0
/* called when a session is created */
BOOL session_claim(user_struct *vuser)
{
	int i = 0;
	TDB_DATA data;
	struct sockaddr sa;
	struct in_addr *client_ip;
	struct sessionid sessionid;
	uint32 pid = (uint32)sys_getpid();
	TDB_DATA key;		
	fstring keystr;
	char * hostname;
	int tdb_store_flag;  /* If using utmp, we do an inital 'lock hold' store,
				but we don't need this if we are just using the 
				(unique) pid/vuid combination */

	vuser->session_keystr = NULL;

	/* don't register sessions for the guest user - its just too
	   expensive to go through pam session code for browsing etc */
	if (vuser->guest) {
		return True;
	}

	if (!tdb) {
		tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 
			       O_RDWR | O_CREAT, 0644);
		if (!tdb) {
			DEBUG(1,("session_claim: failed to open sessionid tdb\n"));
			return False;
		}
	}

	ZERO_STRUCT(sessionid);

	data.dptr = NULL;
	data.dsize = 0;

	if (lp_utmp()) {
		for (i=1;i<MAX_SESSION_ID;i++) {
			slprintf(keystr, sizeof(keystr)-1, "ID/%d", i);
			key.dptr = keystr;
			key.dsize = strlen(keystr)+1;
			
			if (tdb_store(tdb, key, data, TDB_INSERT) == 0) break;
		}
		
		if (i == MAX_SESSION_ID) {
			DEBUG(1,("session_claim: out of session IDs (max is %d)\n", 
				 MAX_SESSION_ID));
			return False;
		}
		slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1, SESSION_UTMP_TEMPLATE, i);
		tdb_store_flag = TDB_MODIFY;
	} else
	{
		slprintf(keystr, sizeof(keystr)-1, "ID/%lu/%u", 
			 (long unsigned int)sys_getpid(), 
			 vuser->vuid);
		slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1, 
			 SESSION_TEMPLATE, (long unsigned int)sys_getpid(), 
			 vuser->vuid);

		key.dptr = keystr;
		key.dsize = strlen(keystr)+1;
			
		tdb_store_flag = TDB_REPLACE;
	}

	/* If 'hostname lookup' == yes, then do the DNS lookup.  This is
           needed because utmp and PAM both expect DNS names 
	   
	   client_name() handles this case internally.
	*/

	hostname = client_name();
	if (strcmp(hostname, "UNKNOWN") == 0) {
		hostname = client_addr();
	}

	fstrcpy(sessionid.username, vuser->user.unix_name);
	fstrcpy(sessionid.hostname, hostname);
	sessionid.id_num = i;  /* Only valid for utmp sessions */
	sessionid.pid = pid;
	sessionid.uid = vuser->uid;
	sessionid.gid = vuser->gid;
	fstrcpy(sessionid.remote_machine, get_remote_machine_name());
	fstrcpy(sessionid.ip_addr, client_addr());

	client_ip = client_inaddr(&sa);

	if (!smb_pam_claim_session(sessionid.username, sessionid.id_str, sessionid.hostname)) {
		DEBUG(1,("pam_session rejected the session for %s [%s]\n",
				sessionid.username, sessionid.id_str));
		if (tdb_store_flag == TDB_MODIFY) {
			tdb_delete(tdb, key);
		}
		return False;
	}

	data.dptr = (char *)&sessionid;
	data.dsize = sizeof(sessionid);
	if (tdb_store(tdb, key, data, tdb_store_flag) != 0) {
		DEBUG(1,("session_claim: unable to create session id record\n"));
		return False;
	}

	if (lp_utmp()) {
		sys_utmp_claim(sessionid.username, sessionid.hostname, 
			       client_ip,
			       sessionid.id_str, sessionid.id_num);
	}

	vuser->session_keystr = strdup(keystr);
	if (!vuser->session_keystr) {
		DEBUG(0, ("session_claim:  strdup() failed for session_keystr\n"));
		return False;
	}
	return True;
}
示例#22
0
struct tdb_print_db *get_print_db_byname(const char *printername)
{
	struct tdb_print_db *p = NULL, *last_entry = NULL;
	int num_open = 0;
	pstring printdb_path;
	BOOL done_become_root = False;

	for (p = print_db_head, last_entry = print_db_head; p; p = p->next) {
		/* Ensure the list terminates... JRA. */
		SMB_ASSERT(p->next != print_db_head);

		if (p->tdb && strequal(p->printer_name, printername)) {
			DLIST_PROMOTE(print_db_head, p);
			p->ref_count++;
			return p;
		}
		num_open++;
		last_entry = p;
	}

	/* Not found. */
	if (num_open >= MAX_PRINT_DBS_OPEN) {
		/* Try and recycle the last entry. */
		DLIST_PROMOTE(print_db_head, last_entry);

		for (p = print_db_head; p; p = p->next) {
			if (p->ref_count)
				continue;
			if (p->tdb) {
				if (tdb_close(print_db_head->tdb)) {
					DEBUG(0,("get_print_db: Failed to close tdb for printer %s\n",
								print_db_head->printer_name ));
					return NULL;
				}
			}
			p->tdb = NULL;
			p->ref_count = 0;
			memset(p->printer_name, '\0', sizeof(p->printer_name));
			break;
		}
		if (p) {
			DLIST_PROMOTE(print_db_head, p);
			p = print_db_head;
		}
	}
       
	if (!p)	{
		/* Create one. */
		p = (struct tdb_print_db *)malloc(sizeof(struct tdb_print_db));
		if (!p) {
			DEBUG(0,("get_print_db: malloc fail !\n"));
			return NULL;
		}
		ZERO_STRUCTP(p);
		DLIST_ADD(print_db_head, p);
	}

	pstrcpy(printdb_path, lock_path("printing/"));
	pstrcat(printdb_path, printername);
	pstrcat(printdb_path, ".tdb");

	if (geteuid() != 0) {
		become_root();
		done_become_root = True;
	}

	p->tdb = tdb_open_log(printdb_path, 5000, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);

	if (done_become_root)
		unbecome_root();

	if (!p->tdb) {
		DEBUG(0,("get_print_db: Failed to open printer backend database %s.\n",
					printdb_path ));
		DLIST_REMOVE(print_db_head, p);
		SAFE_FREE(p);
		return NULL;
	}
	fstrcpy(p->printer_name, printername);
	p->ref_count++;
	return p;
}
示例#23
0
gint main (gint argc, gchar **argv)
{
	struct _CamelLockHelperMsg msg;
	gint len;
	gint res;
	gchar *path;
	fd_set rset;
	struct timeval tv;
	struct _lock_info *info;

	setup_process ();

	do {
		/* do a poll/etc, so we can refresh the .locks as required ... */
		FD_ZERO (&rset);
		FD_SET (STDIN_FILENO, &rset);

		/* check the minimum timeout we need to refresh the next oldest lock */
		if (lock_info_list) {
			time_t now = time (NULL);
			time_t left;
			time_t delay = CAMEL_DOT_LOCK_REFRESH;

			info = lock_info_list;
			while (info) {
				left = CAMEL_DOT_LOCK_REFRESH - (now - info->stamp);
				left = MAX (left, 0);
				delay = MIN (left, delay);
				info = info->next;
			}

			tv.tv_sec = delay;
			tv.tv_usec = 0;
		}

		d (fprintf (stderr, "lock helper waiting for input\n"));
		if (select (STDIN_FILENO + 1, &rset, NULL, NULL, lock_info_list ? &tv : NULL) == -1) {
			if (errno == EINTR)
				break;

			continue;
		}

		/* did we get a timeout?  scan for any locks that need updating */
		if (!FD_ISSET (STDIN_FILENO, &rset)) {
			time_t now = time (NULL);
			time_t left;

			d (fprintf (stderr, "Got a timeout, checking locks\n"));

			info = lock_info_list;
			while (info) {
				left = (now - info->stamp);
				if (left >= CAMEL_DOT_LOCK_REFRESH) {
					lock_touch (info->path);
					info->stamp = now;
				}
				info = info->next;
			}

			continue;
		}

		len = read_n (STDIN_FILENO, &msg, sizeof (msg));
		if (len == 0)
			break;

		res = CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
		if (len == sizeof (msg) && msg.magic == CAMEL_LOCK_HELPER_MAGIC) {
			switch (msg.id) {
			case CAMEL_LOCK_HELPER_LOCK:
				res = CAMEL_LOCK_HELPER_STATUS_NOMEM;
				if (msg.data > 0xffff) {
					res = CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
				} else if ((path = malloc (msg.data + 1)) != NULL) {
					res = CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
					len = read_n (STDIN_FILENO, path, msg.data);
					if (len == msg.data) {
						path[len] = 0;
						res = lock_path (path, &msg.data);
					}
					free (path);
				}
				break;
			case CAMEL_LOCK_HELPER_UNLOCK:
				res = unlock_id (msg.data);
				break;
			}
		}
		d (fprintf (stderr, "returning result %d\n", res));
		msg.id = res;
		msg.magic = CAMEL_LOCK_HELPER_RETURN_MAGIC;
		write_n (STDOUT_FILENO, &msg, sizeof (msg));
	} while (1);

	d (fprintf (stderr, "parent exited, clsoing down remaining id's\n"));
	while (lock_info_list)
		unlock_id (lock_info_list->id);

	return 0;
}
示例#24
0
int main(int argc, char *argv[])
{
    int c;
    static int profile_only = 0;
    TDB_CONTEXT *tdb;
    poptContext pc;
    struct poptOption long_options[] = {
        POPT_AUTOHELP
        {"processes",	'p', POPT_ARG_NONE,	&processes_only, 'p', "Show processes only" },
        {"verbose",	'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
        {"locks",	'L', POPT_ARG_NONE,	&locks_only, 'L', "Show locks only" },
        {"shares",	'S', POPT_ARG_NONE,	&shares_only, 'S', "Show shares only" },
        {"user", 'u', POPT_ARG_STRING,	0, 'u', "Switch to user" },
        {"brief",	'b', POPT_ARG_NONE, 	&brief, 'b', "Be brief" },
#ifdef WITH_PROFILE
        {"profile",	'P', POPT_ARG_NONE,	&profile_only, 'P', "Do profiling" },
#endif /* WITH_PROFILE */
        {"byterange",	'B', POPT_ARG_NONE,	&show_brl, 'B', "Include byte range locks"},
        POPT_COMMON_SAMBA
        POPT_TABLEEND
    };

    setup_logging(argv[0],True);

    dbf = x_stderr;

    if (getuid() != geteuid()) {
        d_printf("smbstatus should not be run setuid\n");
        return(1);
    }

    pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
                        POPT_CONTEXT_KEEP_FIRST);

    while ((c = poptGetNextOpt(pc)) != -1) {
        switch (c) {
        case 'u':
            Ucrit_addUsername(poptGetOptArg(pc));
            break;
        }
    }

    if (verbose) {
        d_printf("using configfile = %s\n", dyn_CONFIGFILE);
    }

    if (!lp_load(dyn_CONFIGFILE,False,False,False)) {
        fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
        return (-1);
    }

    if (profile_only) {
        return profile_dump();
    }

    tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
    if (!tdb) {
        d_printf("sessionid.tdb not initialised\n");
    } else {
        if (locks_only) goto locks;

        d_printf("\nSamba version %s\n",SAMBA_VERSION_STRING);
        d_printf("PID     Username      Group         Machine                        \n");
        d_printf("-------------------------------------------------------------------\n");

        tdb_traverse(tdb, traverse_sessionid, NULL);
        tdb_close(tdb);
    }

    tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
    if (!tdb) {
        d_printf("%s not initialised\n", lock_path("connections.tdb"));
        d_printf("This is normal if an SMB client has never connected to your server.\n");
    }  else  {
        if (verbose) {
            d_printf("Opened %s\n", lock_path("connections.tdb"));
        }

        if (brief)
            exit(0);

        d_printf("\nService      pid     machine       Connected at\n");
        d_printf("-------------------------------------------------------\n");

        tdb_traverse(tdb, traverse_fn1, NULL);
        tdb_close(tdb);
    }

locks:
    if (processes_only) exit(0);

    if (!shares_only) {
        int ret;

        if (!locking_init(1)) {
            d_printf("Can't initialise locking module - exiting\n");
            exit(1);
        }

        ret = share_mode_forall(print_share_mode);

        if (ret == 0) {
            d_printf("No locked files\n");
        } else if (ret == -1) {
            d_printf("locked file list truncated\n");
        }

        d_printf("\n");

        if (show_brl) {
            brl_forall(print_brl);
        }

        locking_end();
    }

    return (0);
}
示例#25
0
文件: statuspage.c 项目: hajuuk/R7000
/* show the current server status */
void status_page(void)
{
	const char *v;
	int autorefresh=0;
	int refresh_interval=30;
	TDB_CONTEXT *tdb;
	int nr_running=0;
	BOOL waitup = False;

	smbd_pid = pidfile_pid("smbd");

	if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
		stop_smbd();
		start_smbd();
		waitup=True;
	}

	if (cgi_variable("smbd_start") || cgi_variable("all_start")) {
		start_smbd();
		waitup=True;
	}

	if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) {
		stop_smbd();
		waitup=True;
	}

	if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) {
		stop_nmbd();
		start_nmbd();
		waitup=True;
	}
	if (cgi_variable("nmbd_start") || cgi_variable("all_start")) {
		start_nmbd();
		waitup=True;
	}

	if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) {
		stop_nmbd();
		waitup=True;
	}

#ifdef WITH_WINBIND
	if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) {
		stop_winbindd();
		start_winbindd();
		waitup=True;
	}

	if (cgi_variable("winbindd_start") || cgi_variable("all_start")) {
		start_winbindd();
		waitup=True;
	}

	if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) {
		stop_winbindd();
		waitup=True;
	}
#endif
	/* wait for daemons to start/stop */
	if (waitup)
		sleep(SLEEP_TIME);
	
	if (cgi_variable("autorefresh")) {
		autorefresh = 1;
	} else if (cgi_variable("norefresh")) {
		autorefresh = 0;
	} else if (cgi_variable("refresh")) {
		autorefresh = 1;
	}

	if ((v=cgi_variable("refresh_interval"))) {
		refresh_interval = atoi(v);
	}

	if (cgi_variable("show_client_in_col_1")) {
		PID_or_Machine = 1;
	}

	if (cgi_variable("show_pid_in_col_1")) {
		PID_or_Machine = 0;
	}

	tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
	if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
 
	initPid2Machine ();

	printf("<H2>%s</H2>\n", _("Server Status"));

	printf("<FORM method=post>\n");

	if (!autorefresh) {
		printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh"));
		printf("<br>%s", _("Refresh Interval: "));
		printf("<input type=text size=2 name=\"refresh_interval\" value=\"%d\">\n", 
		       refresh_interval);
	} else {
		printf("<input type=submit value=\"%s\" name=\"norefresh\">\n", _("Stop Refreshing"));
		printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval);
		printf("<input type=hidden name=\"refresh\" value=\"1\">\n");
	}

	printf("<p>\n");

	if (!tdb) {
		/* open failure either means no connections have been
                   made */
	}


	printf("<table>\n");

	printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING);

	fflush(stdout);
	printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
	if (geteuid() == 0) {
	    if (smbd_running()) {
		nr_running++;
		printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd"));
	    } else {
		printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd"));
	    }
	    printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd"));
	}
	printf("</tr>\n");

	fflush(stdout);
	printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running"));
	if (geteuid() == 0) {
	    if (nmbd_running()) {
		nr_running++;
		printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd"));
	    } else {
		printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd"));
	    }
	    printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd"));    
	}
	printf("</tr>\n");

#ifdef WITH_WINBIND
	fflush(stdout);
	printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running"));
	if (geteuid() == 0) {
	    if (winbindd_running()) {
		nr_running++;
		printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd"));
	    } else {
		printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd"));
	    }
	    printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd"));
	}
	printf("</tr>\n");
#endif

	if (geteuid() == 0) {
	    printf("<tr><td></td><td></td>\n");
	    if (nr_running >= 1) {
	        /* stop, restart all */
		printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All"));
		printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All"));
	    }
	    else if (nr_running == 0) {
	    	/* start all */
		printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All"));
	    }
	    printf("</tr>\n");
	}
	printf("</table>\n");
	fflush(stdout);

	printf("<p><h3>%s</h3>\n", _("Active Connections"));
	printf("<table border=1>\n");
	printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date"));
	if (geteuid() == 0) {
		printf("<th>%s</th>\n", _("Kill"));
	}
	printf("</tr>\n");

	if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);

	printf("</table><p>\n");

	printf("<p><h3>%s</h3>\n", _("Active Shares"));
	printf("<table border=1>\n");
	printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
		_("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));

	if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);

	printf("</table><p>\n");

	printf("<h3>%s</h3>\n", _("Open Files"));
	printf("<table border=1>\n");
	printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", _("PID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date"));

	locking_init(1);
	share_mode_forall(print_share_mode);
	locking_end();
	printf("</table>\n");

	if (tdb) tdb_close(tdb);

	printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1"));
	printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1"));

	printf("</FORM>\n");

	if (autorefresh) {
		/* this little JavaScript allows for automatic refresh
                   of the page. There are other methods but this seems
                   to be the best alternative */
		printf("<script language=\"JavaScript\">\n");
		printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n", 
		       cgi_baseurl(),
		       refresh_interval,
		       refresh_interval*1000);
		printf("//-->\n</script>\n");
	}
}
示例#26
0
int main(int argc, const char *argv[])
{
	int c;
	int profile_only = 0;
	bool show_processes, show_locks, show_shares;
	bool show_notify = false;
	poptContext pc;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"processes",	'p', POPT_ARG_NONE,	NULL, 'p', "Show processes only" },
		{"verbose",	'v', POPT_ARG_NONE, 	NULL, 'v', "Be verbose" },
		{"locks",	'L', POPT_ARG_NONE,	NULL, 'L', "Show locks only" },
		{"shares",	'S', POPT_ARG_NONE,	NULL, 'S', "Show shares only" },
		{"notify",	'N', POPT_ARG_NONE,	NULL, 'N', "Show notifies" },
		{"user", 	'u', POPT_ARG_STRING,	&username, 'u', "Switch to user" },
		{"brief",	'b', POPT_ARG_NONE, 	NULL, 'b', "Be brief" },
		{"profile",     'P', POPT_ARG_NONE, NULL, 'P', "Do profiling" },
		{"profile-rates", 'R', POPT_ARG_NONE, NULL, 'R', "Show call rates" },
		{"byterange",	'B', POPT_ARG_NONE,	NULL, 'B', "Include byte range locks"},
		{"numeric",	'n', POPT_ARG_NONE,	NULL, 'n', "Numeric uid/gid"},
		{"fast",	'f', POPT_ARG_NONE,	NULL, 'f', "Skip checks if processes still exist"},
		POPT_COMMON_SAMBA
		POPT_TABLEEND
	};
	TALLOC_CTX *frame = talloc_stackframe();
	int ret = 0;
	struct messaging_context *msg_ctx = NULL;
	char *db_path;
	bool ok;

	sec_init();
	smb_init_locale();

	setup_logging(argv[0], DEBUG_STDERR);
	lp_set_cmdline("log level", "0");

	if (getuid() != geteuid()) {
		d_printf("smbstatus should not be run setuid\n");
		ret = 1;
		goto done;
	}

	if (getuid() != 0) {
		d_printf("smbstatus only works as root!\n");
		ret = 1;
		goto done;
	}


	pc = poptGetContext(NULL, argc, argv, long_options,
			    POPT_CONTEXT_KEEP_FIRST);

	while ((c = poptGetNextOpt(pc)) != -1) {
		switch (c) {
		case 'p':
			processes_only = true;
			break;
		case 'v':
			verbose = true;
			break;
		case 'L':
			locks_only = true;
			break;
		case 'S':
			shares_only = true;
			break;
		case 'N':
			show_notify = true;
			break;
		case 'b':
			brief = true;
			break;
		case 'u':
			Ucrit_addUid(nametouid(poptGetOptArg(pc)));
			break;
		case 'P':
		case 'R':
			profile_only = c;
			break;
		case 'B':
			show_brl = true;
			break;
		case 'n':
			numeric_only = true;
			break;
		case 'f':
			do_checks = false;
			break;
		}
	}

	/* setup the flags based on the possible combincations */

	show_processes = !(shares_only || locks_only || profile_only) || processes_only;
	show_locks     = !(shares_only || processes_only || profile_only) || locks_only;
	show_shares    = !(processes_only || locks_only || profile_only) || shares_only;

	if ( username )
		Ucrit_addUid( nametouid(username) );

	if (verbose) {
		d_printf("using configfile = %s\n", get_dyn_CONFIGFILE());
	}

	if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n",
			get_dyn_CONFIGFILE());
		ret = -1;
		goto done;
	}


	/*
	 * This implicitly initializes the global ctdbd connection,
	 * usable by the db_open() calls further down.
	 */
	msg_ctx = messaging_init(NULL, samba_tevent_context_init(NULL));
	if (msg_ctx == NULL) {
		fprintf(stderr, "messaging_init failed\n");
		ret = -1;
		goto done;
	}

	if (!lp_load_global(get_dyn_CONFIGFILE())) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n",
			get_dyn_CONFIGFILE());
		ret = -1;
		goto done;
	}

	switch (profile_only) {
		case 'P':
			/* Dump profile data */
			ok = status_profile_dump(verbose);
			return ok ? 0 : 1;
		case 'R':
			/* Continuously display rate-converted data */
			ok = status_profile_rates(verbose);
			return ok ? 0 : 1;
		default:
			break;
	}

	if ( show_processes ) {
		d_printf("\nSamba version %s\n",samba_version_string());
		d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n", "PID", "Username", "Group", "Machine", "Protocol Version", "Encryption", "Signing");
		d_printf("----------------------------------------------------------------------------------------------------------------------------------------\n");

		sessionid_traverse_read(traverse_sessionid, frame);

		if (processes_only) {
			goto done;
		}
	}

	if ( show_shares ) {
		if (brief) {
			goto done;
		}

		d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing");
		d_printf("---------------------------------------------------------------------------------------------\n");

		connections_forall_read(traverse_connections, frame);

		d_printf("\n");

		if ( shares_only ) {
			goto done;
		}
	}

	if ( show_locks ) {
		int result;
		struct db_context *db;

		db_path = lock_path("locking.tdb");
		if (db_path == NULL) {
			d_printf("Out of memory - exiting\n");
			ret = -1;
			goto done;
		}

		db = db_open(NULL, db_path, 0,
			     TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
			     DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);

		if (!db) {
			d_printf("%s not initialised\n", db_path);
			d_printf("This is normal if an SMB client has never "
				 "connected to your server.\n");
			TALLOC_FREE(db_path);
			exit(0);
		} else {
			TALLOC_FREE(db);
			TALLOC_FREE(db_path);
		}

		if (!locking_init_readonly()) {
			d_printf("Can't initialise locking module - exiting\n");
			ret = 1;
			goto done;
		}

		result = share_entry_forall(print_share_mode, NULL);

		if (result == 0) {
			d_printf("No locked files\n");
		} else if (result < 0) {
			d_printf("locked file list truncated\n");
		}

		d_printf("\n");

		if (show_brl) {
			brl_forall(print_brl, NULL);
		}

		locking_end();
	}

	if (show_notify) {
		struct notify_context *n;

		n = notify_init(talloc_tos(), msg_ctx,
				messaging_tevent_context(msg_ctx));
		if (n == NULL) {
			goto done;
		}
		notify_walk(n, print_notify_rec, NULL);
		TALLOC_FREE(n);
	}

done:
	TALLOC_FREE(frame);
	return ret;
}
示例#27
0
BOOL claim_connection(connection_struct *conn, const char *name,int max_connections,BOOL Clear, uint32 msg_flags)
{
	struct connections_key key;
	struct connections_data crec;
	TDB_DATA kbuf, dbuf;

	if (!tdb)
		tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 
			       O_RDWR | O_CREAT, 0644);

	if (!tdb)
		return False;

	/*
	 * Enforce the max connections parameter.
	 */

	if (max_connections > 0) {
		struct count_stat cs;

		cs.mypid = sys_getpid();
		cs.curr_connections = 0;
		cs.name = lp_servicename(SNUM(conn));
		cs.Clear = Clear;

		/*
		 * This has a race condition, but locking the chain before hand is worse
		 * as it leads to deadlock.
		 */

		if (tdb_traverse(tdb, count_fn, &cs) == -1) {
			DEBUG(0,("claim_connection: traverse of connections.tdb failed with error %s.\n",
				tdb_errorstr(tdb) ));
			return False;
		}

		if (cs.curr_connections >= max_connections) {
			DEBUG(1,("claim_connection: Max connections (%d) exceeded for %s\n",
				max_connections, name ));
			return False;
		}
	}

	DEBUG(5,("claiming %s %d\n",name,max_connections));

	make_conn_key(conn, name, &kbuf, &key);

	/* fill in the crec */
	ZERO_STRUCT(crec);
	crec.magic = 0x280267;
	crec.pid = sys_getpid();
	crec.cnum = conn?conn->cnum:-1;
	if (conn) {
		crec.uid = conn->uid;
		crec.gid = conn->gid;
		safe_strcpy(crec.name,
			    lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
	}
	crec.start = time(NULL);
	crec.bcast_msg_flags = msg_flags;
	
	safe_strcpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine)-1);
	safe_strcpy(crec.addr,conn?conn->client_address:client_addr(),sizeof(crec.addr)-1);

	dbuf.dptr = (char *)&crec;
	dbuf.dsize = sizeof(crec);

	if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) {
		DEBUG(0,("claim_connection: tdb_store failed with error %s.\n",
			tdb_errorstr(tdb) ));
		return False;
	}

	return True;
}
示例#28
0
文件: status.c 项目: aosm/samba
 int main(int argc, char *argv[])
{
	int c;
	int profile_only = 0;
	TDB_CONTEXT *tdb;
	BOOL show_processes, show_locks, show_shares;
	poptContext pc;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"processes",	'p', POPT_ARG_NONE,	&processes_only, 'p', "Show processes only" },
		{"verbose",	'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
		{"locks",	'L', POPT_ARG_NONE,	&locks_only, 'L', "Show locks only" },
		{"shares",	'S', POPT_ARG_NONE,	&shares_only, 'S', "Show shares only" },
		{"user", 	'u', POPT_ARG_STRING,	&username, 'u', "Switch to user" },
		{"brief",	'b', POPT_ARG_NONE, 	&brief, 'b', "Be brief" },
		{"profile",     'P', POPT_ARG_NONE, NULL, 'P', "Do profiling" },
		{"profile-rates", 'R', POPT_ARG_NONE, NULL, 'R', "Show call rates" },
		{"byterange",	'B', POPT_ARG_NONE,	&show_brl, 'B', "Include byte range locks"},
		{"numeric",	'n', POPT_ARG_NONE,	&numeric_only, 'n', "Numeric uid/gid"},
		{"counts",	'C', POPT_ARG_NONE,	&show_counts, 'n', "Show all user op/bytes counts"},
		POPT_COMMON_SAMBA
		POPT_TABLEEND
	};

	sec_init();
	load_case_tables();

	setup_logging(argv[0],True);
	
	dbf = x_stderr;
	
	if (getuid() != geteuid()) {
		d_printf("smbstatus should not be run setuid\n");
		return(1);
	}

	pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 
			    POPT_CONTEXT_KEEP_FIRST);
	
	while ((c = poptGetNextOpt(pc)) != -1) {
		switch (c) {
		case 'u':                                      
			Ucrit_addUid(nametouid(poptGetOptArg(pc)));
			break;
		case 'P':
		case 'R':
			profile_only = c;
		}
	}

	/* setup the flags based on the possible combincations */

	show_processes = !(shares_only || locks_only || profile_only) || processes_only;
	show_locks     = !(shares_only || processes_only || profile_only) || locks_only;
	show_shares    = !(processes_only || locks_only || profile_only) || shares_only;

	if ( username )
		Ucrit_addUid( nametouid(username) );

	if (verbose) {
		d_printf("using configfile = %s\n", dyn_CONFIGFILE);
	}

	if (!lp_load(dyn_CONFIGFILE,False,False,False,True)) {
		fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
		return (-1);
	}

	switch (profile_only) {
		case 'P':
			/* Dump profile data */
			return status_profile_dump(verbose);
		case 'R':
			/* Continuously display rate-converted data */
			return status_profile_rates(verbose);
		default:
			break;
	}

	if ( show_processes ) {
		tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
		if (!tdb) {
			d_printf("sessionid.tdb not initialised\n");
		} else {
			d_printf("\nSamba version %s\n",SAMBA_VERSION_STRING);
			d_printf("PID     Username      Group         Machine                        \n");
			d_printf("-------------------------------------------------------------------\n");

			tdb_traverse(tdb, traverse_sessionid, NULL);
			tdb_close(tdb);
		}

		if (processes_only) 
			exit(0);	
	}
  
#if WITH_DARWIN_STATS
	if ( show_counts) {
		dump_user_stats();
		dump_service_stats();
		exit(0);
	}
#endif /*WITH_DARWIN_STATS*/

	if ( show_shares ) {
		tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
		if (!tdb) {
			d_printf("%s not initialised\n", lock_path("connections.tdb"));
			d_printf("This is normal if an SMB client has never connected to your server.\n");
		}  else  {
			if (verbose) {
				d_printf("Opened %s\n", lock_path("connections.tdb"));
			}

			if (brief) 
				exit(0);
		
			d_printf("\nService      pid     machine       Connected at\n");
			d_printf("-------------------------------------------------------\n");
	
			tdb_traverse(tdb, traverse_fn1, NULL);
			tdb_close(tdb);

			d_printf("\n");
		}

		if ( shares_only )
			exit(0);
	}

	if ( show_locks ) {
		int ret;

		tdb = tdb_open_log(lock_path("locking.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);

		if (!tdb) {
			d_printf("%s not initialised\n", lock_path("locking.tdb"));
			d_printf("This is normal if an SMB client has never connected to your server.\n");
			exit(0);
		} else {
			tdb_close(tdb);
		}

		if (!locking_init(1)) {
			d_printf("Can't initialise locking module - exiting\n");
			exit(1);
		}
		
		ret = share_mode_forall(print_share_mode, NULL);

		if (ret == 0) {
			d_printf("No locked files\n");
		} else if (ret == -1) {
			d_printf("locked file list truncated\n");
		}
		
		d_printf("\n");

		if (show_brl) {
			brl_forall(print_brl);
		}
		
		locking_end();
	}

	return (0);
}