Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 May 2010 15:41:23 GMT
From:      Efstratios Karatzas <gpf@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 178954 for review
Message-ID:  <201005291541.o4TFfN7K059004@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@178954?ac=10

Change 178954 by gpf@gpf_desktop on 2010/05/29 15:41:06

	- ended up creating a new function, nfsrv_auditpath(), which is 
	actually a wrapper around the KPIs that try to acquire a path 
	from a vnode. Now the code is short and clean, xD.
	Tested and everything seems fine.
	
	Only thing left is to do is log the other arguments of the VOPs.
	(at least for sys/nfsserver/*)

Affected files ...

.. //depot/projects/soc2010/gpf_audit/freebsd/src/sys/nfsserver/nfs_serv.c#11 edit

Differences ...

==== //depot/projects/soc2010/gpf_audit/freebsd/src/sys/nfsserver/nfs_serv.c#11 (text+ko) ====

@@ -196,6 +196,99 @@
 }
 
 /*
+ * Do our best to acquire 'a' working path for vp
+ * 
+ * vp		-	vnode in question
+ * dvp		-	directory with vp as a child
+ * fname	-	name used to reference vp inside dvp
+ * fhp		-	file handle for vp
+ * n		-	AUDIT_ARG_UPATH1 or AUDIT_ARG_UPATH2
+ */
+static void
+nfsrv_auditpath(struct vnode *vp, struct vnode *dvp, char *fname, fhandle_t *fhp, int n)
+{
+	char path[PATH_MAX];
+	struct thread *td;
+	char *fullpath, *freepath;
+	char success;
+
+	td = curthread;
+	freepath = NULL;
+	success = 0;
+	
+	/* try to find the path through vp */
+	if (vp != NULL) {
+		/* try the cache */
+		vn_fullpath_global(td, vp, &fullpath, &freepath);
+		if (freepath != NULL) {
+			success = 1;
+			goto out;
+		}
+
+		/* if our cache fails us */
+		if (fhp != NULL && vp->v_mount != NULL) {
+			uint64_t parent_hint;
+			/* get the hint stored inside the file handle */
+			VFS_FHHINT(vp->v_mount, &fhp->fh_fid, &parent_hint);
+			vn_fullpath_nocache(vp, &fullpath, &freepath,
+				parent_hint, PARENTHINT | WANTNAME);
+			if (freepath != NULL) {
+				success = 1;
+				goto out;
+			}
+		}
+	}
+
+	/* try to find the path through dvp and the component name used to reference vp */
+	if (dvp != NULL && fname != NULL) {
+		/* try the cache */
+		vn_fullpath_global(td, dvp, &fullpath, &freepath);
+		if (freepath != NULL) {
+			snprintf(path, sizeof(path), "%s/%s", fullpath, fname);
+			fullpath = path;
+			success = 1;
+			goto out;
+		}
+
+		/* if our cache fails us */
+		vn_fullpath_nocache(dvp, &fullpath, &freepath,
+			0, WANTNAME);
+		if (freepath != NULL) {
+			snprintf(path, sizeof(path), "%s/%s", fullpath, fname);
+			fullpath = path;
+			success = 1;
+			goto out;
+		}
+	}
+	
+	/* last resort, just save the name used to reference the file in question */
+	if (fname != NULL) {
+		strlcpy(path, fname, sizeof(path));
+		fullpath = path;
+		success = 1;
+	}
+
+out:		
+	if (success) {
+		switch (n) {
+		case 1:
+			AUDIT_ARG_UPATH1(td, fullpath);
+			break;
+		case 2:
+			AUDIT_ARG_UPATH2(td, fullpath);
+			break;
+		default:
+			AUDIT_ARG_UPATH1(td, fullpath);
+			break;
+		}
+	}
+	
+	if (freepath != NULL) {
+		free(freepath, M_TEMP);
+	}
+}
+
+/*
  * nfs v3 access service
  */
 int
@@ -267,36 +360,15 @@
 	if (vp)
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
-			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			AUDIT_ARG_VNODE1(AUDIT_vp);			
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -354,36 +426,15 @@
 	if (vp)
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
-			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			AUDIT_ARG_VNODE1(AUDIT_vp);			
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -546,36 +597,15 @@
 		vput(vp);
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
-			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			AUDIT_ARG_VNODE1(AUDIT_vp);			
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -613,7 +643,6 @@
 	nfsm_srvnamesiz(len);
 
 	pubflag = nfs_ispublicfh(fhp);
-
 	nd.ni_cnd.cn_cred = cred;
 	nd.ni_cnd.cn_nameiop = LOOKUP;
 	nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART | MPSAFE | WANTPARENT;
@@ -766,36 +795,15 @@
 		vrele(ndp->ni_dvp);
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return (error);
 }
 
@@ -907,36 +915,15 @@
 	if (vp)
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (link_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-			
 			AUDIT_ARG_VNODE1(link_vp);
-	
-			freepath = NULL;
-			vn_fullpath_global(td, link_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && link_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(link_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(link_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			nfsrv_auditpath(link_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -1190,36 +1177,15 @@
 	if (vp)
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (new_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(new_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, new_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && new_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(new_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(new_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			nfsrv_auditpath(new_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -1441,36 +1407,15 @@
 		vput(vp);
 	vn_finished_write(mntp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
+
 	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (new_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(new_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, new_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && new_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(new_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(new_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					AUDIT_ARG_UPATH1(td, fullpath);
-					free(freepath, M_TEMP);
-				}
-			}
+			nfsrv_auditpath(new_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -1769,51 +1714,14 @@
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		if (nd.ni_vp != NULL && nd.ni_dvp != NULL) {
-			char path[PATH_MAX];
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-		
+		nfsrv_auditpath(nd.ni_vp, nd.ni_dvp, nd.ni_cnd.cn_pnbuf, fhp, 1);
+		if (nd.ni_vp != NULL)
 			AUDIT_ARG_VNODE1(nd.ni_vp);
-			
-			/* save the name of the new file in case everything fails */
-			if (nd.ni_cnd.cn_pnbuf != NULL)
-				strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
-			
-			freepath = NULL;
-			vn_fullpath_global(td, nd.ni_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				strlcpy(path, fullpath, sizeof(path));
-				free(freepath, M_TEMP);
-			}
-			/* if we fail to acquire a path from the new vnode, use the directory vnode instead */
-			else if (nd.ni_cnd.cn_pnbuf != NULL) {
-				vn_fullpath_global(td, nd.ni_dvp, &fullpath, &freepath);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-				/* if our cache fails us */
-				else if (fhp != NULL && nd.ni_vp->v_mount != NULL) {
-					uint64_t parent_hint;
-					/* get the hint stored inside the file handle */
-					VFS_FHHINT(nd.ni_vp->v_mount, &fhp->fh_fid, &parent_hint);
-					vn_fullpath_nocache(nd.ni_vp, &fullpath, &freepath,
-						parent_hint, PARENTHINT | WANTNAME);
-					if (freepath != NULL) {
-						strlcpy(path, fullpath, sizeof(path));
-						free(freepath, M_TEMP);
-					}
-				}
-			}
+	}
 
-			AUDIT_ARG_UPATH1(td, path);
-		}
-	}
-	
 	return (error);
 }
 
@@ -2006,10 +1914,13 @@
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);	
 
-	/* XXX audit */
-	/* return (0); */
-	error = 0;
-	goto audit;
+	/* XXX AUDIT */
+	if (AUDITING_TD(curthread)) {
+		nfsrv_auditpath(AUDIT_vp, AUDIT_dvp, nd.ni_cnd.cn_pnbuf, fhp, 1);
+		if (AUDIT_vp != NULL)
+			AUDIT_ARG_VNODE1(AUDIT_vp);
+	}
+	return (0);
 nfsmout:
 	if (nd.ni_dvp) {
 		if (nd.ni_dvp == nd.ni_vp)
@@ -2028,51 +1939,11 @@
 	VFS_UNLOCK_GIANT(vfslocked);
 
 audit:
-	/* XXX AUDIT */	
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		char path[PATH_MAX];
-		struct thread *td = curthread;
-		char *fullpath, *freepath;
-
-		/* save the name of the new node in case everything fails */
-		if (nd.ni_cnd.cn_pnbuf != NULL)
-			strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
-			
-		freepath = NULL;
-		if (AUDIT_vp != NULL) {
-			AUDIT_ARG_VNODE1(AUDIT_vp);			
-			if (AUDIT_vp != NULL)
-				vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-				
-			if (freepath != NULL) {
-				strlcpy(path, fullpath, sizeof(path));
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
-				uint64_t parent_hint;
-				/* get the hint stored inside the file handle */
-				VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
-				vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
-					parent_hint, PARENTHINT | WANTNAME);
-				if (freepath != NULL) {
-					strlcpy(path, fullpath, sizeof(path));
-					free(freepath, M_TEMP);
-				}
-			}
-		}		
-		/* if we haven't acquired a path, try to grab the parent directory path instead */
-		if (freepath == NULL && AUDIT_dvp != NULL) {
-			if (nd.ni_cnd.cn_pnbuf != NULL) {
-				vn_fullpath_global(td, AUDIT_dvp, &fullpath, &freepath);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-			}
-		}
-
-		AUDIT_ARG_UPATH1(td, path);
+		nfsrv_auditpath(AUDIT_vp, AUDIT_dvp, nd.ni_cnd.cn_pnbuf, fhp, 1);
+		if (AUDIT_vp != NULL)
+			AUDIT_ARG_VNODE1(AUDIT_vp);
 	}
 
 	return (error);
@@ -2194,33 +2065,7 @@
 
 	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		struct thread *td = curthread;
-		char path[PATH_MAX];
-		char *fullpath, *freepath;
-
-		if (parent_dvp != NULL && nd.ni_cnd.cn_pnbuf != NULL) {
-			/* save the name of the deleted file in case everything fails */
-			strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
-
-			/* use the directory vnode to acquire the old path */
-			freepath = NULL;
-			vn_fullpath_global(td, parent_dvp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else if (fhp != NULL && parent_dvp->v_mount != NULL) {
-				vn_fullpath_nocache(parent_dvp, &fullpath, &freepath,
-					0, WANTNAME);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-			}
-
-			AUDIT_ARG_UPATH1(td, path);
-		}
+		nfsrv_auditpath(NULL, parent_dvp, nd.ni_cnd.cn_pnbuf, NULL, 1);
 	}
 
 	return(error);
@@ -2462,64 +2307,15 @@
 
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
+
 	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		struct thread *td = curthread;
-		char path[PATH_MAX];
-		char *fullpath, *freepath;
-		
-		if (from_dvp != NULL && fromnd.ni_cnd.cn_pnbuf != NULL) {
-			/* save the old name of old file in case everything fails */
-			strlcpy(path, fromnd.ni_cnd.cn_pnbuf, sizeof(path));
-
-			/* use the directory vnode to acquire the old path */
-			freepath = NULL;
-			vn_fullpath_global(td, from_dvp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				snprintf(path, sizeof(path), "%s/%s", fullpath, fromnd.ni_cnd.cn_pnbuf);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else {
-				vn_fullpath_nocache(from_dvp, &fullpath, &freepath,
-					0, WANTNAME);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, fromnd.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-			}
-			AUDIT_ARG_UPATH1(td, path);
-		}
-
-		if (vp != NULL) {
+		nfsrv_auditpath(NULL, from_dvp, fromnd.ni_cnd.cn_pnbuf, NULL, 1);
+		if (vp != NULL)
 			AUDIT_ARG_VNODE1(vp);
-		}
+		nfsrv_auditpath(NULL, to_dvp, tond.ni_cnd.cn_pnbuf, NULL, 2);		
+	}
 
-		if (to_dvp != NULL && tond.ni_cnd.cn_pnbuf != NULL) {
-			/* save the new name of the file in case everything fails */
-			strlcpy(path, tond.ni_cnd.cn_pnbuf, sizeof(path));
-			
-			/* use the directory vnode to acquire the new path */
-			freepath = NULL;
-			vn_fullpath_global(td, to_dvp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				snprintf(path, sizeof(path), "%s/%s", fullpath, tond.ni_cnd.cn_pnbuf);
-				free(freepath, M_TEMP);
-			}
-			/* if our cache fails us */
-			else {
-				vn_fullpath_nocache(to_dvp, &fullpath, &freepath,
-					0, WANTNAME);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, tond.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-			}
-			AUDIT_ARG_UPATH2(td, path);
-		}
-	} /* AUDIT */
-	
 	return (error);
 }
 
@@ -2672,38 +2468,15 @@
 		vrele(nd.ni_vp);
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		char path[PATH_MAX];
-		struct thread *td = curthread;
-		char *fullpath, *freepath;
-		
-		if (parent_dir_vp != NULL && nd.ni_cnd.cn_pnbuf != NULL) {
-			freepath = NULL;
-			vn_fullpath_global(td, parent_dir_vp, &fullpath, &freepath);
-			if (freepath != NULL && nd.ni_cnd.cn_pnbuf) {
-				snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-				free(freepath, M_TEMP);
-			}
-			
-			AUDIT_ARG_UPATH1(td, path);
-		}
-		
-		if (vp != NULL) {
+		nfsrv_auditpath(NULL, parent_dir_vp, nd.ni_cnd.cn_pnbuf, NULL, 1);
+		if (vp != NULL)
 			AUDIT_ARG_VNODE1(vp);
+		nfsrv_auditpath(vp, NULL, NULL, fhp, 2);		
+	}
 
-			freepath = NULL;
-			vn_fullpath_global(td, vp, &fullpath, &freepath);			
-			if (freepath != NULL) {
-				strlcpy(path, fullpath, sizeof(path));
-				free(freepath, M_TEMP);
-			}
-			
-			AUDIT_ARG_UPATH2(td, path);
-		}
-	}
-	
 	return(error);
 }
 
@@ -2895,39 +2668,14 @@
 
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		if (symlink_vp != NULL && parent_dir_vp != NULL) {
-			char path[PATH_MAX];
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-		
+		nfsrv_auditpath(symlink_vp, parent_dir_vp, nd.ni_cnd.cn_pnbuf, fhp, 1);
+		if (symlink_vp != NULL)
 			AUDIT_ARG_VNODE1(symlink_vp);
-			
-			freepath = NULL;
-			vn_fullpath_global(td, symlink_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				strlcpy(path, fullpath, sizeof(path));
-				free(freepath, M_TEMP);
-			}
-			/* if we fail to acquire a path from the new vnode, use the directory vnode instead */
-			else if (nd.ni_cnd.cn_pnbuf != NULL) {
-				vn_fullpath_global(td, parent_dir_vp, &fullpath, &freepath);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-				/* last resort: just save the name of the new file */
-				else {
-					strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
-				}
-			}
-			
-			AUDIT_ARG_UPATH1(td, path);
-		}
 	}
-	
+
 	return (error);
 }
 
@@ -3095,39 +2843,14 @@
 		vrele(dirp);
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		if (new_dir_vp != NULL && parent_dir_vp != NULL) {
-			char path[PATH_MAX];
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-		
+		nfsrv_auditpath(new_dir_vp, parent_dir_vp, nd.ni_cnd.cn_pnbuf, fhp, 1);
+		if (new_dir_vp != NULL)
 			AUDIT_ARG_VNODE1(new_dir_vp);
-			
-			freepath = NULL;
-			vn_fullpath_global(td, new_dir_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				strlcpy(path, fullpath, sizeof(path));
-				free(freepath, M_TEMP);
-			}
-			/* if we fail to acquire a path from the new vnode, use the directory vnode instead */
-			else if (nd.ni_cnd.cn_pnbuf != NULL) {		
-				vn_fullpath_global(td, parent_dir_vp, &fullpath, &freepath);
-				if (freepath != NULL) {
-					snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-					free(freepath, M_TEMP);
-				}
-				/* last resort: just save the name of the new file */
-				else {
-					strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
-				}
-			}
-			
-			AUDIT_ARG_UPATH1(td, path);
-		}
 	}
-	
+
 	return (error);
 }
 
@@ -3259,29 +2982,12 @@
 
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
+
 	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		struct thread *td = curthread;
-		char path[PATH_MAX];
-		char *fullpath, *freepath;
+		nfsrv_auditpath(NULL, parent_dvp, nd.ni_cnd.cn_pnbuf, NULL, 1);
+	}
 
-		if (parent_dvp != NULL && nd.ni_cnd.cn_pnbuf != NULL) {
-			/* use the directory vnode to acquire the old path */
-			freepath = NULL;
-			vn_fullpath_global(td, parent_dvp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
-				free(freepath, M_TEMP);
-			}
-			/* last resort: just save the name of the deleted dir */
-			else {
-				strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
-			}
-			AUDIT_ARG_UPATH1(td, path);
-		}
-	}
-	
 	return(error);
 }
 
@@ -3617,24 +3323,14 @@
 	if (vp)
 		vrele(vp);
 	VFS_UNLOCK_GIANT(vfslocked);	
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		if (dir_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-			
+		nfsrv_auditpath(dir_vp, NULL, NULL, fhp, 1);
+		if (dir_vp != NULL)
 			AUDIT_ARG_VNODE1(dir_vp);
-	
-			freepath = NULL;
-			vn_fullpath_global(td, dir_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-		}
 	}
-	
+
 	return(error);
 }
 
@@ -3988,24 +3684,14 @@
 	if (vp)
 		vrele(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
-		if (dir_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-			
+		nfsrv_auditpath(dir_vp, NULL, NULL, fhp, 1);
+		if (dir_vp != NULL)
 			AUDIT_ARG_VNODE1(dir_vp);
-	
-			freepath = NULL;
-			vn_fullpath_global(td, dir_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
-		}
 	}
-	
+
 	return(error);
 }
 
@@ -4173,24 +3859,15 @@
 		vput(vp);
 	vn_finished_write(mp);
 	VFS_UNLOCK_GIANT(vfslocked);
-	
-	/* XXX AUDIT */	
+
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
-	
+
 	return(error);
 }
 
@@ -4290,20 +3967,11 @@
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
 
-	/* XXX AUDIT */	
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
 
@@ -4388,20 +4056,11 @@
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
 
-	/* XXX AUDIT */	
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
 
@@ -4484,20 +4143,11 @@
 		vput(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
 
-	/* XXX AUDIT */	
+	/* XXX AUDIT */
 	if (AUDITING_TD(curthread)) {
 		if (AUDIT_vp != NULL) {
-			struct thread *td = curthread;
-			char *fullpath, *freepath;
-
 			AUDIT_ARG_VNODE1(AUDIT_vp);
-
-			freepath = NULL;
-			vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
-			if (freepath != NULL) {
-				AUDIT_ARG_UPATH1(td, fullpath);
-				free(freepath, M_TEMP);
-			}
+			nfsrv_auditpath(AUDIT_vp, NULL, NULL, fhp, 1);
 		}
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005291541.o4TFfN7K059004>