20 #include <sys/types.h>
28 #include <seclabel_api.h>
30 #include "ms_example.h"
34 static char *optstr =
"u371m:d:p:w:M:D:P:W:o:O:r:l:R:y:C:iaqsAvf:kK:B:";
37 static char *default_recip =
"/CN=P7User1/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
39 static const char text[] =
"First line\r\nSecond line\r\n";
40 static char *binary_data;
42 static char *fwd_subject =
"Forwarded message subject";
44 static int add_binary_attachment (
45 struct X400msMessage *mp,
46 char * filename_to_send
48 static int add_fwd_bp (
49 struct X400msMessage *mp,
54 struct X400msMessage *mp
56 static void usage(
void) ;
69 struct X400msSession *sp;
70 struct X400msMessage *mp;
71 struct X400Recipient *rp;
77 if (get_args(argc, argv, optstr)) {
82 printf(
"Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
83 contype = ic_fgetc(x400_contype, stdin);
85 ic_fgetc(x400_contype, stdin);
87 if ( contype <
'0' ||
'2' < contype )
88 contype = x400_contype;
93 def_oraddr = x400_ms_user_addr;
94 def_dn = x400_ms_user_dn;
95 def_pa = x400_ms_presentation_address;
97 def_oraddr = x400_mta_user_addr;
98 def_dn = x400_mta_user_dn;
99 def_pa = x400_mta_presentation_address;
102 printf(
"Your ORAddress [%s] > ", def_oraddr);
103 ic_fgets (orn,
sizeof orn, stdin);
105 if ( (strlen(orn) > 0) && (orn[strlen(orn)-1] ==
'\n') )
106 orn[strlen(orn)-1] =
'\0';
109 strcpy(orn, def_oraddr);
112 printf (
"Password [%s]: ",
113 contype == 0 ? x400_p7_password : x400_p3_password);
114 if ( ic_fgets (buffer,
sizeof buffer, stdin) == NULL )
117 if ((strlen(buffer) > 0) && (buffer[strlen(buffer)-1] ==
'\n') )
118 buffer[strlen(buffer)-1] =
'\0';
119 if (buffer[0] ==
'\0')
120 strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
123 printf(
"Presentation Address [%s] > ", def_pa);
124 ic_fgets (pa,
sizeof pa, stdin);
126 if ( (strlen(pa) > 0) && (pa[strlen(pa)-1] ==
'\n'))
127 pa[strlen(pa)-1] =
'\0';
132 if (talking_to_marben_ms)
136 status =
X400msOpen (contype, orn, def_dn, buffer, pa, NULL, &sp);
138 fprintf (stderr,
"Error in Open: %s\n",
X400msError (status));
142 if (talking_to_marben_ms)
167 if (x400_default_recipient != NULL)
168 recip = x400_default_recipient;
170 recip = default_recip;
172 printf(
"Message recipient [%s]: ", recip);
173 ic_fgets (tmp,
sizeof tmp, stdin);
175 if ( (strlen(tmp) > 0) && (tmp[strlen(tmp)-1] ==
'\n') )
176 tmp[strlen(tmp)-1] =
'\0';
177 if (strlen(tmp) != 0)
180 printf(
"Subject [%s]: ", subject);
181 ic_fgets (tmp,
sizeof tmp, stdin);
183 if ( (strlen(tmp) > 0) && (tmp[strlen(tmp)-1] ==
'\n') )
184 tmp[strlen(tmp)-1] =
'\0';
185 if (strlen(tmp) != 0)
186 subject = strdup(tmp);
190 fprintf (stderr,
"x400msMsgNew returned error: %s\n",
X400msError (status));
196 fprintf (stderr,
"x400msRecipNew returned error: %s\n",
X400msError (status));
202 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
208 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
214 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
220 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
225 printf(
"delivery report request %d ( 1 - No, 2 - Yes)\n", x400_dr_req);
228 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
233 printf(
"read notification request %d ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n", x400_rn_req);
236 fprintf (stderr,
"x400msRecipAddIntParam returned error: %s\n",
X400msError (status));
241 char *contid =
"ContID00001";
246 fprintf (stderr,
"X400msMsgAddIntParam %d returned error: %s\n",
255 fprintf (stderr,
"X400msMsgAddIntParam %d returned error: %s\n",
261 printf(
"message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
262 x400_default_priority);
267 printf(
"military message priority is %d ( 0 - low, 1 - high)\n",
268 x400_default_priority);
276 char tmp_buffer[255];
278 snprintf(tmp_buffer, 244,
"%s '%s' '%.19s'",
279 subject, get_x400_pty_str_from_4406(x400_default_priority), ctime(&t));
280 printf(
"Subject is '%s'\n", tmp_buffer);
283 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
292 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
298 fprintf (stderr,
"x400ms returned error: %s\n",
X400msError (status));
305 printf(
"failed to add X400_T_IA5TEXT BP\n");
310 if (filename_to_send != NULL) {
311 status = add_binary_attachment (mp, filename_to_send);
313 printf(
"failed to add X400_T_BINARY BP\n");
316 status = add_fwd_bp (mp, orn, def_dn);
318 printf(
"failed to add forwarded BP\n");
322 printf(
"no binary file set - not sending X400_T_BINARY\n");
323 printf(
"no binary file set - not sending forwarded BP\n");
327 status = add_ftbp(mp);
329 printf(
"failed to add X400_T_BINARY BP\n");
336 #define XML_BUFSIZE 1024
337 #define STRING_BUFSIZE 1024
339 const char* xml_filename =
"seclabel.xml";
340 char xml_content[XML_BUFSIZE];
341 char str_content[STRING_BUFSIZE];
342 int str_len = STRING_BUFSIZE;
346 fd = fopen(xml_filename,
"r");
348 fprintf(stderr,
"Failed to open %s : %s\n",
349 xml_filename,strerror(errno));
352 fread(&xml_content,XML_BUFSIZE,1,fd);
356 status = SecLabelInit(
"Example program");
357 if (status != SECLABEL_E_NOERROR) {
358 fprintf(stderr,
"SecLabelInit returned error %d\n", status);
363 status = SecLabelParse(xml_content,
368 if (status != SECLABEL_E_NOERROR) {
369 fprintf(stderr,
"SecLabelParse returned error %d\n", status);
375 str_content,str_len);
377 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
386 fprintf (stderr,
"x400msMsgSend returned error: %s\n",
X400msError (status));
390 struct X400Recipient *irp;
400 fprintf(stderr,
"A recipient with ");
405 fprintf (stderr,
"ORAddress %s ", buf);
411 fprintf (stderr,
" and DN %s", buf);
413 fprintf (stderr,
" was rejected\n");
424 printf(
"Message submitted successfully\n");
428 fprintf(stderr,
"No MessageId present from submission result: error %d\n", status);
431 printf(
"MessageId from Submission Result = %s\n", buf);
436 fprintf(stderr,
"No MessageSubmissionTime present from submission result: error %d\n", status);
439 printf(
"MessageSubmissionTime from Submission Result = %s\n", buf);
444 fprintf(stderr,
"No ContentIdentifier present from submission result: error %d\n", status);
447 printf(
"ContentIdentifier from Submission Result = %s\n", buf);
455 fprintf(stderr,
"Failed to get raw message length: error %d\n", status);
457 struct X400msMessage *newmsg;
460 databuf = (
char *)malloc(retlen);
461 printf(
"Data buffer length required = %d\n", (
int)retlen);
464 fprintf(stderr,
"Failed to get raw message: error %d\n", status);
467 FILE *fd = fopen(
"message.dump",
"w");
469 fprintf(stderr,
"Failed to open file message.dump\n");
471 if (fwrite(databuf, 1, retlen, fd) < retlen) {
472 fprintf(stderr,
"Failed to write message to file message.dump\n");
474 fprintf(stdout,
"Dumped message to file message.dump\n");
483 fprintf(stderr,
"Failed to create message from bytes: error %d\n", status);
492 fprintf (stderr,
"x400msMsgDelete returned error: %s\n",
X400msError (status));
504 static int add_binary_attachment (
505 struct X400msMessage *mp,
515 printf(
"sending file %s\n", filename);
516 if ((fd = open (filename_to_send, O_RDONLY)) == -1) {
517 printf(
"Failed to open content file %s: ", filename);
522 if (fstat(fd, &buf) != 0) {
524 printf(
"Can't fstat file %s %d", filename, errno);
528 file_size = buf.st_size;
529 printf(
"Content file size = %d\n", file_size);
531 binary_data = (
char *) malloc(file_size);
532 if ( binary_data == NULL )
535 if ((fs = read(fd, binary_data, file_size) ) == -1) {
536 printf(
"Cannot read from binary file %d\n", errno);
543 printf(
"failed to add X400_T_BINARY BP\n");
549 static int add_fwd_bp (
550 struct X400msMessage *mp,
555 struct X400Message *x400_mp;
556 struct X400Recipient *rp;
560 printf(
"sending fwd bp \n");
564 fprintf (stderr,
"x400MsgNew returned error: %s\n",
X400msError (status));
569 "090909090909Z", (
size_t)-1);
571 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
576 "090909090909Z", (
size_t)-1);
578 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
585 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
590 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
597 fprintf (stderr,
"x400RecipNew returned error: %s\n",
X400msError (status));
604 fprintf (stderr,
"x400RecipAddStrParam returned error: %s\n",
X400msError (status));
611 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
618 fprintf (stderr,
"X400MsgAddRecip returned error: %s\n",
X400msError (status));
621 printf(
"Put %s in as originator\n", orig_orn);
626 fprintf (stderr,
"x400RecipNew returned error: %s\n",
X400msError (status));
632 fprintf (stderr,
"x400RecipAddStrParam returned error: %s\n",
X400msError (status));
638 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
644 fprintf (stderr,
"X400MsgAddRecip returned error: %s\n",
X400msError (status));
647 printf(
"Put %s in as reipient\n", recip);
653 fprintf (stderr,
"x400RecipNew returned error: %s\n",
X400msError (status));
659 fprintf (stderr,
"x400RecipAddStrParam returned error: %s\n",
X400msError (status));
665 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
673 fprintf (stderr,
"X400MsgAddRecip returned error: %s\n",
X400msError (status));
676 printf(
"Put %s in as reipient\n", recip);
682 printf(
"message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
683 x400_default_priority);
688 printf(
"military message priority is %d ( 0 - low, 1 - high)\n",
689 x400_default_priority);
697 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
704 printf(
"failed to add X400_T_IA5TEXT BP\n");
712 fprintf (stderr,
"x400ms returned error: %s\n",
X400msError (status));
723 fprintf (stderr,
"X400msMsgAddMessageBody returned error: %s\n",
X400msError (status));
732 struct X400msMessage *mp
739 struct X400Bodypart *bp;
742 if (filename_to_send == NULL) {
743 printf(
"no file set - not sending X400_T_FTBP\n");
746 fp = fopen(filename_to_send,
"rb");
747 if (fp == (FILE *)NULL) {
748 printf(
"Cannot open binary file\n");
751 binary_data = (
char *) malloc(bin_bp_size);
752 if ( binary_data == NULL )
754 if ((fs = fread (binary_data,
sizeof(
char),
755 bin_bp_size/
sizeof(
char), fp) ) == -1) {
756 printf(
"Cannot read from binary file\n");
762 if (fs < bin_bp_size) {
763 printf(
"Cannot read %d bytes from binary file (got %d)\n",
772 "Test FTBP File", -1);
777 "20230801060101.0Z", -1);
779 "20230801060202.0Z", -1);
785 printf(
"failed to add X400_T_FTBP BP\n");
788 printf(
"Sent %d bytes as X400_T_FTBP BP\n", fs);
792 static void usage(
void) {
793 printf(
"usage: %s\n", optstr);
794 printf(
"\t where:\n");
795 printf(
"\t -u : Don't prompt to override defaults \n");
796 printf(
"\t -3 : Use P3 connection \n");
797 printf(
"\t -7 : Use P7 connection \n");
798 printf(
"\t -1 : Use Marben-compatibility mode for P7 connection \n");
799 printf(
"\t -m : OR Address in P7 bind arg \n");
800 printf(
"\t -d : DN in P7 bind arg \n");
801 printf(
"\t -p : Presentation Address of P7 Store \n");
802 printf(
"\t -w : P7 password of P7 user \n");
803 printf(
"\t -M : OR Address in P3 bind arg \n");
804 printf(
"\t -D : DN in P3 bind arg \n");
805 printf(
"\t -P : Presentation Address of P3 server\n");
806 printf(
"\t -W : P3 password of P3 user \n");
807 printf(
"\t -o : Originator \n");
808 printf(
"\t -O : Originator Return Address \n");
809 printf(
"\t -r : Recipient\n");
810 printf(
"\t -l : Logline\n");
811 printf(
"\t -R : Report setting: 0=none, 1=-ve, 2=+ve\n");
812 printf(
"\t -y : Military Priority \n");
813 printf(
"\t\t 0 - deferred, 1 - routine, 2 - priority \n");
814 printf(
"\t\t 3 - immediate, 4 - flash, 5 - override \n");
815 printf(
"\t -C : Content Type (2/22/772/OID) \n");
816 printf(
"\t -i : Implicit conversion prohibited = TRUE \n");
817 printf(
"\t -a : Alternate Recipient Prohibited = TRUE \n");
818 printf(
"\t -q : Content Return Request = TRUE \n");
819 printf(
"\t -s : Disclosure of Recipient = FALSE \n");
820 printf(
"\t -A : Recipient Reassignment Prohibited = FALSE \n");
821 printf(
"\t -v : Conversion with Loss Prohibited = FALSE \n");
822 printf(
"\t -f : Filename to transfer as binary bp\n");
823 printf(
"\t -k : Request Delivery Report\n");
824 printf(
"\t -K : Request Read Notification ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n");
825 printf(
"\t -B : Set alternative subject line \n");
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
#define X400_N_STRICT_P7_1988
#define X400_S_LOG_CONFIGURATION_FILE
int X400BodypartNew(int type, struct X400Bodypart **bpp)
Create a new body part object.
int X400msMsgSend(struct X400msMessage *mp)
Send message object.
#define X400_N_CONTENT_RETURN_REQUEST
int X400msMsgAddAttachment(struct X400msMessage *mp, int type, const char *string, size_t length)
Add attachment to the message.
int X400msOpen(int type, const char *oraddr, const char *dirname, const char *credentials, const char *pa, int *messages, struct X400msSession **spp)
Open a session to a Message Store (P7) or MTA (P3) in synchronous mode.
#define X400_S_GRAPHIC_CHARSETS
#define X400_S_FTBP_CONTENT_DESCRIPTION
int X400MsgAddIntParam(struct X400Message *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
int X400msMsgAddBodypart(struct X400msMessage *mp, struct X400Bodypart *bp)
#define X400_N_NUM_ATTACHMENTS
#define X400_S_SECURITY_LABEL
int X400BodypartAddIntParam(struct X400Bodypart *bp, int paramtype, int value)
Add integer-valued parameter to the body part.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
#define X400_E_RECIPIENT_ERROR
int X400msMsgAddIntParam(struct X400msMessage *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msRecipAddIntParam(struct X400Recipient *rp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msRecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
#define X400_S_DIRECTORY_NAME
int X400MsgAddRecip(struct X400Message *mp, int reciptype, struct X400Recipient *recip)
Add a recipient object to the message.
int X400RecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the recipient.
#define X400_S_MESSAGE_DELIVERY_TIME
int X400msRecipNew(struct X400msMessage *mp, int type, struct X400Recipient **rpp)
Add new recipient to a message.
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
#define X400_S_FTBP_CREATION_DATE
#define X400_S_FTBP_MODIFICATION_DATE
#define X400_RECIP_STANDARD
#define X400_N_MMTS_PRIORITY_QUALIFIER
int X400msMsgNew(struct X400msSession *sp, int type, struct X400msMessage **mpp)
Creates new message.
#define X400_N_USE_EXTENDED_SUBJECT
#define X400_S_CONTENT_IDENTIFIER
#define X400_S_MESSAGE_IDENTIFIER
#define X400_N_REPORT_REQUEST
int X400msMsgFromRaw(struct X400msSession *sp, char *buffer, size_t buflen, struct X400msMessage **mpp, int *typep)
Reconstruct a message from a binary representation.
int X400msRecipGet(struct X400msMessage *mp, int type, int number, struct X400Recipient **rpp)
Get recipient object from message.
int X400msRecipGetStrParam(struct X400Recipient *rp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the recipient object.
#define X400_S_EXTERNAL_CONTENT_TYPE
X400 MA/MS (P3/P7) Interface.
#define X400_N_FTBP_OBJECT_SIZE
int X400msMsgGetRaw(struct X400msSession *sp, struct X400msMessage *mp, char *buffer, size_t buflen, size_t *buflenp)
Get a binary representation of a message which can be subsequently be used to reconstruct the message...
int X400MsgAddStrParam(struct X400Message *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msMsgAddMessageBody(struct X400msMessage *mp, struct X400Message *mbp)
int X400MsgAddAttachment(struct X400Message *mp, int type, const char *string, size_t length)
Add an attachment to the message.
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
#define X400_S_FTBP_FILENAME
#define X400_RECIP_INVALID
#define X400_N_NOTIFICATION_REQUEST
int X400MsgNew(int type, struct X400Message **mpp)
Creates new message.
#define X400_S_MESSAGE_SUBMISSION_TIME
int X400msMsgGetStrParam(struct X400msMessage *mp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the message object.
#define X400_N_ERROR_DUPLICATE_ATTRIBUTE
int X400msMsgAddStrParam(struct X400msMessage *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400BodypartAddStrParam(struct X400Bodypart *bp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the body part.
#define X400_S_OR_ADDRESS
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.
#define X400_S_TELETEX_CHARSETS