*/
#include "includes.h"
+#include "system/passwd.h"
+#include "system/filesys.h"
+#include "printing.h"
+#include "util_tdb.h"
+
+#ifdef malloc
+#undef malloc
+#endif
-#define PRINT_TDB "/tmp/vlp.tdb"
#define PRINT_FIRSTJOB "100"
static TDB_CONTEXT *tdb;
static void usage(void)
{
- printf("Usage: print-test lpq|lprm|print|queuepause|queueresume|"
+ printf("Usage: vlp tdbfile=/tmp/vlp.tdb lpq|lprm|print|queuepause|queueresume|"
"lppause|lpresume [args]\n");
}
static void set_printer_status(char *printer, int status)
{
fstring keystr;
- int result;
slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer);
- result = tdb_store_int32(tdb, keystr, status);
+ tdb_store_int32(tdb, keystr, status);
}
static int get_printer_status(char *printer)
job_list[i].size,
(i == 0 && job_list[i].status == LPQ_QUEUED) ?
LPQ_SPOOLING : job_list[i].status,
- job_list[i].submit_time, job_list[i].owner,
+ (long int)job_list[i].submit_time, job_list[i].owner,
job_list[i].jobname);
job_count++;
}
struct passwd *pw;
TDB_DATA value, queue;
struct vlp_job job;
- int i;
if (argc < 3) {
printf("Usage: print <printername> <jobname>\n");
/* Create a job record */
- for (i = 2; i < argc; i++) {
- fstrcat(job.jobname, argv[i]);
- if (i < argc - 1) {
- fstrcat(job.jobname, " ");
- }
- }
+ slprintf(job.jobname, sizeof(job.jobname) - 1, "%s", argv[2]);
- if (!(pw = getpwuid(getuid()))) {
+ if (!(pw = getpwuid(geteuid()))) {
+ printf("getpwuid failed\n");
return 1;
}
- fstrcpy(job.owner, pw->pw_name);
+ slprintf(job.owner, sizeof(job.owner) - 1, "%s", pw->pw_name);
job.jobid = next_jobnum(printer);
job.size = 666;
/* Add job to end of queue */
- queue.dptr = (unsigned char *)SMB_MALLOC(value.dsize +
- sizeof(struct vlp_job));
+ queue.dptr = (unsigned char *)malloc(value.dsize + sizeof(struct vlp_job));
if (!queue.dptr) return 1;
memcpy(queue.dptr, value.dptr, value.dsize);
int main(int argc, char **argv)
{
/* Parameter check */
+ const char *printdb_path = NULL;
- if (argc == 1) {
+ if (argc < 2) {
usage();
return 1;
}
- /* Initialise */
+ if (strncmp(argv[1], "tdbfile", strlen("tdbfile")) != 0) {
+ usage();
+ return 1;
+ }
+
+ printdb_path = get_string_param(argv[1]);
+ if (!printdb_path) {
+ return 1;
+ }
- if (!(tdb = tdb_open(PRINT_TDB, 0, 0, O_RDWR | O_CREAT,
- 0666))) {
- printf("%s: unable to open %s\n", argv[0], PRINT_TDB);
+ /* FIXME: We should *never* open a tdb without logging! */
+ if (!(tdb = tdb_open_compat(printdb_path, 0, 0, O_RDWR | O_CREAT,
+ 0666, NULL, NULL))) {
+ printf("%s: unable to open %s\n", argv[0], printdb_path);
return 1;
}
/* Ensure we are modes 666 */
- chmod(PRINT_TDB, 0666);
+ chmod(printdb_path, 0666);
/* Do commands */
- if (strcmp(argv[1], "lpq") == 0) {
- return lpq_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "lpq") == 0) {
+ return lpq_command(argc - 2, &argv[2]);
}
- if (strcmp(argv[1], "lprm") == 0) {
- return lprm_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "lprm") == 0) {
+ return lprm_command(argc - 2, &argv[2]);
}
- if (strcmp(argv[1], "print") == 0) {
- return print_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "print") == 0) {
+ return print_command(argc - 2, &argv[2]);
}
- if (strcmp(argv[1], "queuepause") == 0) {
- return queuepause_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "queuepause") == 0) {
+ return queuepause_command(argc - 2, &argv[2]);
}
- if (strcmp(argv[1], "queueresume") == 0) {
- return queueresume_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "queueresume") == 0) {
+ return queueresume_command(argc - 2, &argv[2]);
}
- if (strcmp(argv[1], "lppause") == 0) {
- return lppause_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "lppause") == 0) {
+ return lppause_command(argc - 2, &argv[2]);
}
- if (strcmp(argv[1], "lpresume") == 0) {
- return lpresume_command(argc - 1, &argv[1]);
+ if (strcmp(argv[2], "lpresume") == 0) {
+ return lpresume_command(argc - 2, &argv[2]);
}
/* Unknown command */