summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.printf/bin4.stp
diff options
context:
space:
mode:
authorDavid Smith <dsmith@redhat.com>2008-09-12 13:18:15 -0500
committerDavid Smith <dsmith@redhat.com>2008-09-12 13:18:15 -0500
commitee928e1461d33322e9485f4736ba2f979a3331b5 (patch)
tree2290a279f629f4592fbef58952a1f43b9e6e6a86 /testsuite/systemtap.printf/bin4.stp
parent3a4e19b8a7d12cb7e3b82b523bd47b9ae9ff9487 (diff)
downloadsystemtap-steved-ee928e1461d33322e9485f4736ba2f979a3331b5.tar.gz
systemtap-steved-ee928e1461d33322e9485f4736ba2f979a3331b5.tar.xz
systemtap-steved-ee928e1461d33322e9485f4736ba2f979a3331b5.zip
BZ 6755 fix. Wait until all callbacks are finished.
2008-09-12 David Smith <dsmith@redhat.com> BZ 6755 * task_finder.c: Added 'inuse' count to know when handlers are still running. (__stp_utrace_task_finder_report_clone): If state isn't correct, detach. Increase 'inuse' count when starting, decrement when exiting. (__stp_utrace_task_finder_report_exec): Ditto. (__stp_utrace_task_finder_target_death): Ditto. (__stp_utrace_task_finder_target_quiesce): Increase 'inuse' count when starting, decrement when exiting. (__stp_utrace_task_finder_target_syscall_entry): Ditto. (__stp_utrace_task_finder_target_syscall_exit): Ditto. (stap_stop_task_finder): Wait until all callbacks are finished.
Diffstat (limited to 'testsuite/systemtap.printf/bin4.stp')
0 files changed, 0 insertions, 0 deletions
a> 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
/* 
   Unix SMB/CIFS implementation.
   session handling for utmp and PAM

   Copyright (C) tridge@samba.org       2001
   Copyright (C) abartlet@samba.org     2001
   Copyright (C) Gerald (Jerry) Carter  2006   
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/* a "session" is claimed when we do a SessionSetupX operation
   and is yielded when the corresponding vuid is destroyed.

   sessions are used to populate utmp and PAM session structures
*/

#include "includes.h"
#include "smbd/globals.h"
#include "dbwrap.h"

/********************************************************************
 called when a session is created
********************************************************************/

bool session_claim(struct smbd_server_connection *sconn, user_struct *vuser)
{
	struct server_id pid = sconn_server_id(sconn);
	TDB_DATA data;
	int i = 0;
	struct sessionid sessionid;
	fstring keystr;
	struct db_record *rec;
	NTSTATUS status;

	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->server_info->guest) {
		return True;
	}

	if (!sessionid_init()) {
		return False;
	}

	ZERO_STRUCT(sessionid);

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

	if (lp_utmp()) {

		for (i=1;i<MAX_SESSION_ID;i++) {

			/*
			 * This is very inefficient and needs fixing -- vl
			 */

			struct server_id sess_pid;

			snprintf(keystr, sizeof(keystr), "ID/%d", i);

			rec = sessionid_fetch_record(NULL, keystr);
			if (rec == NULL) {
				DEBUG(1, ("Could not lock \"%s\"\n", keystr));
				return False;
			}

			if (rec->value.dsize != sizeof(sessionid)) {
				DEBUG(1, ("Re-using invalid record\n"));
				break;
			}

			memcpy(&sess_pid,
			       ((char *)rec->value.dptr)
			       + offsetof(struct sessionid, pid),
			       sizeof(sess_pid));

			if (!process_exists(sess_pid)) {
				DEBUG(5, ("%s has died -- re-using session\n",
					  procid_str_static(&sess_pid)));
				break;
			}

			TALLOC_FREE(rec);
		}

		if (i == MAX_SESSION_ID) {
			SMB_ASSERT(rec == NULL);
			DEBUG(1,("session_claim: out of session IDs "
				 "(max is %d)\n", MAX_SESSION_ID));
			return False;
		}

		snprintf(sessionid.id_str, sizeof(sessionid.id_str),
			 SESSION_UTMP_TEMPLATE, i);
	} else
	{
		snprintf(keystr, sizeof(keystr), "ID/%s/%u",
			 procid_str_static(&pid), vuser->vuid);

		rec = sessionid_fetch_record(NULL, keystr);
		if (rec == NULL) {
			DEBUG(1, ("Could not lock \"%s\"\n", keystr));
			return False;
		}

		snprintf(sessionid.id_str, sizeof(sessionid.id_str),
			 SESSION_TEMPLATE, (long unsigned int)sys_getpid(),
			 vuser->vuid);
	}

	SMB_ASSERT(rec != NULL);

	/* 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.
	*/

	fstrcpy(sessionid.username, vuser->server_info->unix_name);
	fstrcpy(sessionid.hostname, sconn->client_id.name);
	sessionid.id_num = i;  /* Only valid for utmp sessions */
	sessionid.pid = pid;
	sessionid.uid = vuser->server_info->utok.uid;
	sessionid.gid = vuser->server_info->utok.gid;
	fstrcpy(sessionid.remote_machine, get_remote_machine_name());
	fstrcpy(sessionid.ip_addr_str, sconn->client_id.addr);
	sessionid.connect_start = time(NULL);

	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));

		TALLOC_FREE(rec);
		return False;
	}

	data.dptr = (uint8 *)&sessionid;
	data.dsize = sizeof(sessionid);

	status = rec->store(rec, data, TDB_REPLACE);

	TALLOC_FREE(rec);

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1,("session_claim: unable to create session id "
			 "record: %s\n", nt_errstr(status)));
		return False;
	}

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

	vuser->session_keystr = talloc_strdup(vuser, keystr);
	if (!vuser->session_keystr) {
		DEBUG(0, ("session_claim:  talloc_strdup() failed for session_keystr\n"));
		return False;
	}
	return True;
}

/********************************************************************
 called when a session is destroyed
********************************************************************/

void session_yield(user_struct *vuser)
{
	struct sessionid sessionid;
	struct db_record *rec;

	if (!vuser->session_keystr) {
		return;
	}

	rec = sessionid_fetch_record(NULL, vuser->session_keystr);
	if (rec == NULL) {
		return;
	}

	if (rec->value.dsize != sizeof(sessionid))
		return;

	memcpy(&sessionid, rec->value.dptr, sizeof(sessionid));

	if (lp_utmp()) {
		sys_utmp_yield(sessionid.username, sessionid.hostname, 
			       sessionid.ip_addr_str,
			       sessionid.id_str, sessionid.id_num);
	}

	smb_pam_close_session(sessionid.username, sessionid.id_str,
			      sessionid.hostname);

	rec->delete_rec(rec);

	TALLOC_FREE(rec);
}

/********************************************************************