1#include <stdio.h> 2#include <stdlib.h> 3#include <string.h> 4#include <errno.h> 5#include <libsmbclient.h> 6 7#define MAX_BUFF_SIZE 255 8char g_workgroup[MAX_BUFF_SIZE]; 9char g_username[MAX_BUFF_SIZE]; 10char g_password[MAX_BUFF_SIZE]; 11char g_server[MAX_BUFF_SIZE]; 12char g_share[MAX_BUFF_SIZE]; 13 14char g_print_user[MAX_BUFF_SIZE]; 15char g_print_name[MAX_BUFF_SIZE]; 16unsigned int g_print_id; 17unsigned int g_print_priority; 18unsigned int g_print_size; 19 20unsigned int print_ids[MAX_BUFF_SIZE]; 21unsigned int print_id_count; 22int call_flag; 23 24void auth_fn(const char *server, const char *share, char *workgroup, int wgmaxlen, 25 char *username, int unmaxlen, char *password, int pwmaxlen) 26{ 27 28 strncpy(workgroup, g_workgroup, wgmaxlen - 1); 29 30 strncpy(username, g_username, unmaxlen - 1); 31 32 strncpy(password, g_password, pwmaxlen - 1); 33 34 strcpy(g_server, server); 35 strcpy(g_share, share); 36 37} 38 39void print_list_fn_2(struct print_job_info *pji) 40{ 41 42 print_ids[print_id_count] = pji->id; 43 print_id_count++; 44 45 /* fprintf(stdout, "Call to Second Print Function - Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n", 46 pji->id, pji->priority, pji->size, pji->user, pji->name); */ 47 48} 49 50void print_list_fn(struct print_job_info *pji) 51{ 52 53 g_print_id = pji->id; 54 g_print_priority = pji->priority; 55 g_print_size = pji->size; 56 strcpy(g_print_user,pji->user); 57 strcpy(g_print_name,pji->name); 58 59 /* fprintf(stdout, "Call to First Print Function - Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n", 60 pji->id, pji->priority, pji->size, pji->user, pji->name); */ 61 62} 63 64int main(int argc, char** argv) 65{ 66 int err = -1; 67 int fd = 0; 68 unsigned int i = 0; 69 int msg_len = 0; 70 char url[MAX_BUFF_SIZE]; 71 char* message; 72 73 bzero(g_workgroup,MAX_BUFF_SIZE); 74 bzero(url,MAX_BUFF_SIZE); 75 bzero(g_print_user,MAX_BUFF_SIZE); 76 bzero(g_print_name,MAX_BUFF_SIZE); 77 78 g_print_id = 0; 79 g_print_priority = 0; 80 g_print_size = 0; 81 82 print_id_count = 0; 83 84 if ( argc == 7 ) 85 { 86 87 strncpy(g_workgroup,argv[1],strlen(argv[1])); 88 strncpy(g_username,argv[2],strlen(argv[2])); 89 strncpy(g_password,argv[3],strlen(argv[3])); 90 strncpy(url,argv[4],strlen(argv[4])); 91 92 msg_len = strlen(argv[5])+1; 93 message = malloc(msg_len); 94 message[msg_len - 1] = 0; 95 strncpy(message,argv[5],msg_len); 96 /* printf("Message: %s\n",message); */ 97 /* printf("Message len: %i\n",msg_len); */ 98 99 smbc_init(auth_fn, 0); 100 smbc_unlink(url); 101 fd = smbc_open(url,O_RDWR | O_CREAT, 0666); 102 smbc_write(fd, message, msg_len); 103 smbc_close(fd); 104 105 free(message); 106 107 smbc_print_file(url,argv[6]); 108 smbc_print_file(url,argv[6]); 109 smbc_print_file(url,argv[6]); 110 111 smbc_list_print_jobs(argv[6],print_list_fn); 112 113 if ( smbc_unlink_print_job(argv[6],g_print_id) == 0 ) 114 { 115 if ( smbc_list_print_jobs(argv[6],print_list_fn_2) == 0 ) 116 { 117 err = 0; 118 119 for ( i=0; i<print_id_count; i++ ) 120 { 121 if ( g_print_id == print_ids[i] ) 122 { 123 err = 1; 124 break; 125 } 126 127 } 128 } 129 130 } else 131 err = 1; 132 133 134 135 136 } 137 138 return err; 139 140} 141 142