Written by Urs-Jakob Rüetschi
as part of the pracc project.

Pracc Files, v2

Printer Accounting Files (or pracc files for short) record printing credits and debits. Usually, there is one pracc file per user that is subjected to printer accounting. one pracc file for each user with printer accounting enabled. Printer accounting with pracc files works like that:

There is a number of command line tools to manipulate pracc files and there is a C language API for using pracc files in your own software. Direct manipulation of pracc files is not recommended.

Location and permissions

Pracc files live in /var/print/pracc/, are owned by root, have a special group pracc, and permissions 660. Therefore, pracc files cannot be modified by users other than through tools with appropriate rights. Such tools must make sure that users do not tamper with pracc files.

/var/print/pracc/      2770 root:pracc
/var/print/pracc/user   660 root:pracc
/var/print/pracc.log    660 root:pracc

The location of pracc files and the special group for pracc files can be determined at compile-time in the pracc.h header file.

Format of pracc files

Line by line, each terminated with LF (ASCII 10). Lines must not be longer than MAXLINE, defined in the pracc.h header file.

The first line in a pracc file is the header line:

#pracc-v2-offset-username [comments]

The #pracc-v2 part identifies the file as a version 2 pracc file; offset is either zero or a byte offset into the pracc file, pointing to the most recent reset line (to speed up account summation, currently unused); and username tells whose pracc file this is (useful for tools that get a pracc file on standard input). Optional comments may follow.

All lines start with a special character that identifies the line type. What follows depends on the line type but usually includes a timestamp and a user name, telling when the entry was created and by whom.

#blabla
Comment line, ignored.
 
$k timestamp user {info}
Limit line, defining the minimum balance required for printing: printing is allowed if balance>k. The limit can be set to minus infinity with k=* (an asterisk). This is also the default if there is no limit line in the file. It means unlimited printing. Typically, there is no limit for teachers and a limit of zero for students. Limit lines later in the file override earlier ones.
 
+n timestamp user {info}
Credit line, the account's balance is increased by n.
 
-n timestamp user {info}
Debit line, the account's balance is decreased by n. The info part should give information about the print job.
 
=n timestamp user {info}
Reset line, n is new credit, all prior credit and debit lines are ignored (and should occassionally be deleted). The info part should contain some descriptive text; see the examples below.
 
! timestamp user {info}
Error: Something went wrong. Typically, the user tried to access an invalid account or the number of pages printed could not be determined. The info part should describe the error.

All other lines should be ignored.

The timestamp is an at (@) sign followed by 16 hexadecimal digits; for example:

@4000000042cda28c

The hex digits represent a 64-bit integer that counts the number of seconds that elapsed since the beginning of 1970 plus 4611686018427387914 (which is 10+2^62 or 400000000000000a hex). This is based on the current real time standard, Temps Atomic International, or TAI. The example timestamp above refers to 2005-07-07 21:45:38 TAI. See http://cr.yp.to/time.html for more information on TAI.

Examples

An initial pracc file is created:

#pracc-v2-0-wimmer Waldemar Immerfroh
$9 @4000000042cda28c root minimum balance 
=500 @4000000042cda28c root initial credit 

After user wimmer has printed three jobs:

#pracc-v2-0-wimmer Waldemar Immerfroh
$9 @4000000042cda28c root minimum balance 
=500 @4000000042cda28c root initial credit 
-10 @4000000042ce54a7 wimmer printer walze pages 1 job myfile.ps 
-50 @4000000042ce6403 wimmer printer walze pages 5 job report.ps 
-20 @4000000042ce9522 wimmer printer walze pages 2 job other.doc 

User wimmer got more credit:

#pracc-v2-0-wimmer Waldemar Immerfroh
$9 @4000000042cda28c root minimum balance 
=500 @4000000042cda28c root initial credit 
-10 @4000000042ce54a7 wimmer printer walze pages 1 job myfile.ps 
-50 @4000000042ce6403 wimmer printer walze pages 5 job report.ps 
-20 @4000000042ce9522 wimmer printer walze pages 2 job other.doc 
+500 @4000000042cf0665 root an early Xmas present ;-) 

Use a tool to check the current balance:

# pracc-sum wimmer
acct wimmer balance 920 limit 9 ok

After printing many more jobs, user wimmer runs out of credits:

# pracc-sum wimmer
acct wimmer balance -20 limit 9 bad

User wimmer buys new credits. Then the purging operation is performed. The resulting pracc file looks like this:

#pracc-v2-0-wimmer Waldemar Immerfroh
$9 @4000000042cda28c root minimum balance 
=500 @4000000042cda28c root initial credit 
=30 @4000000043341ac2 root balance 
+1000 @4000000043341ac2 root new credits bought 

The sequence of debits and credits was accumulated and the resulting balance written to the new pracc file in place of the individual debit and credit lines. All comment lines were preserved. Finally, the credit software appended a credit line according to the amount of credits bought.


Changes wrt pracc v1

V1 pracc files had group ownership lp so that LPRng could directly append a debit line.

The limit line in pracc files is new with v2.

Timestamp format changed with v2.

Note that most pracc tools work with both versions because they only evaluate the first field on every line and ignore unknown line types.

v1, ujr/2003-11-13
v2, ujr/2005-06-18
latest: 2006-01-07