aboutsummaryrefslogtreecommitdiff
path: root/testcases/kernel/syscalls/acct/acct02.c
diff options
context:
space:
mode:
authorrobbiew <robbiew>2002-12-04 17:58:14 +0000
committerrobbiew <robbiew>2002-12-04 17:58:14 +0000
commitfc30028deaba1a9f4940c10a03ba63ae9be05cdf (patch)
tree65e071db4fc2ec546690cdf867c73e17030fa009 /testcases/kernel/syscalls/acct/acct02.c
parentb617b0f097e5d6deaee7d3c311c711bf56893780 (diff)
downloadltp-fc30028deaba1a9f4940c10a03ba63ae9be05cdf.tar.gz
Initial checkin of acct() tests.
Diffstat (limited to 'testcases/kernel/syscalls/acct/acct02.c')
-rw-r--r--testcases/kernel/syscalls/acct/acct02.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/testcases/kernel/syscalls/acct/acct02.c b/testcases/kernel/syscalls/acct/acct02.c
new file mode 100644
index 000000000..ee18d16d3
--- /dev/null
+++ b/testcases/kernel/syscalls/acct/acct02.c
@@ -0,0 +1,115 @@
+/*
+ *
+ * Copyright (c) International Business Machines Corp., 2002
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* 12/03/2002 Port to LTP robbiew@us.ibm.com */
+/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
+
+/*
+ * NAME
+ * acct02.c -- test acct
+ *
+ * CALLS
+ * acct
+ *
+ * ALGORITHM
+ * issue calls to acct and test the returned values against
+ * expected results
+ *
+ * RESTRICTIONS
+ * This must run root since the acct call may only be done
+ * by root. Use the TERM flag, to clean up files.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/types.h>
+
+/** LTP Port **/
+#include "test.h"
+#include "usctest.h"
+
+#define FAILED 0
+#define PASSED 1
+
+extern int errno;
+
+char *TCID="acct02"; /* Test program identifier. */
+int TST_TOTAL=2; /* Total number of test cases. */
+extern int Tst_count; /* Test Case counter for tst_* routines */
+/**************/
+
+char fname[80];
+struct passwd *ltpuser;
+
+/*--------------------------------------------------------------*/
+int main (argc, argv)
+ int argc;
+ char *argv[];
+{
+
+ /* Get the user id "nobody" */
+ if ((ltpuser = getpwnam("nobody")) == NULL) {
+ tst_resm(TBROK,"nobody not found in /etc/passwd\n");
+ tst_exit();
+ }
+
+ /* Switch to "nobody" */
+ setuid(ltpuser->pw_uid);
+
+ /* make a temp directory and cd to it */
+ tst_tmpdir();
+
+/*--------------------------------------------------------------*/
+
+ /* turn off acct, so we are in a known state
+ */
+ if( acct( (char*) 0 ) != -1 ) {
+ tst_resm(TBROK, "Non-root attempting to disable acct: didn't fail\n", errno );
+ tst_exit();
+ }
+
+ if( errno != EPERM ) {
+ tst_resm(TBROK, "Non-root acct disable - errno expect: %d got: %d\n",
+ EPERM, errno );
+ tst_exit();
+ } else tst_resm(TPASS, "Received expected error: EPERM");
+
+//-------------------------------------------------
+ if( acct( "/anystring" ) != -1 ) {
+ tst_resm(TBROK, "Non-root attempting to enable acct: didn't fail\n", errno );
+ tst_exit();
+ }
+
+ if( errno != EPERM ) {
+ tst_resm(TFAIL, "Non-root acct enable - errno expect: %d got: %d\n",
+ EPERM, errno );
+ tst_exit();
+ } else tst_resm(TPASS, "Received expected error: EPERM");
+
+//-------------------------------------------------
+
+/* Clean up any files created by test before call to tst_exit. */
+ tst_rmdir();
+ tst_exit(); /* THIS CALL DOES NOT RETURN - EXITS!! */
+/*--------------------------------------------------------------*/
+ return(0);
+}