Following diff changes accton(8) behavior.
If the file given as parameter doesn't exists, accton will create it.
Then it will check the ownership and will make it root:wheel if
it's different.
I added a check to be sure it's run as root because it's has no use if
not run as root.
I don't often write C, if the logic is good but the C implementation
wrong I'm open to critic.
The -f test and touch in /etc/rc won't be needed anymore with this
change.
Index: accton.8
===================================================================
RCS file: /home/reposync/src/usr.sbin/accton/accton.8,v
retrieving revision 1.11
diff -u -p -r1.11 accton.8
--- accton.8 10 Nov 2019 20:51:53 -0000 1.11
+++ accton.8 30 Oct 2020 17:27:36 -0000
@@ -36,7 +36,7 @@
.Nm accton
.Op Ar file
.Sh DESCRIPTION
-With an argument naming an existing
+With an argument naming a
.Ar file ,
.Nm
causes system accounting information for every process executed
Index: accton.c
===================================================================
RCS file: /home/reposync/src/usr.sbin/accton/accton.c,v
retrieving revision 1.8
diff -u -p -r1.8 accton.c
--- accton.c 27 Oct 2009 23:59:50 -0000 1.8
+++ accton.c 30 Oct 2020 17:26:31 -0000
@@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/
+#include <sys/stat.h>
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
@@ -47,6 +48,10 @@ int
main(int argc, char *argv[])
{
int ch;
+ struct stat info_file;
+
+ if(getuid() != 0)
+ err(1, "need root privileges");
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
@@ -63,6 +68,15 @@ main(int argc, char *argv[])
err(1, NULL);
break;
case 1:
+ if(stat(*argv,&info_file) != 0)
+ if(fopen(*argv,"w"))
+ if(stat(*argv,&info_file))
+ err(1, "file %s couldn't be created",
*argv);
+
+ if (info_file.st_uid != 0 || info_file.st_gid != 0)
+ if(chown(*argv, 0, 0) != 0)
+ err(1, "Impossible to fix %s ownership", *argv);
+
if (acct(*argv))
err(1, "%s", *argv);
break;