]> git.saurik.com Git - apple/security.git/blob - Keychain/ExecCLITool.h
Security-163.tar.gz
[apple/security.git] / Keychain / ExecCLITool.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18 #ifndef _H_EXECCLITOOL
19 #define _H_EXECCLITOOL
20
21 #include <sys/types.h>
22 #include <sys/ioctl.h>
23 #include <sys/uio.h>
24 #include <sys/stat.h>
25 #include <sys/mman.h>
26 #include <stdarg.h>
27 #include <signal.h>
28 #include <fcntl.h>
29 #include <cstdio>
30 #include <cstdarg>
31 #include <map>
32 #include <stdlib.h>
33 #include <CoreFoundation/CFString.h>
34
35 class VAArgList
36 {
37 public:
38 VAArgList() {};
39 ~VAArgList() { if (argv) free(argv); }
40
41 typedef const char * ArgvArgPtr;
42
43 int VAArgList::set(const char *path,va_list params);
44
45 const char* const*get() { return argv; }
46
47 int size() { return argn; }
48
49 private:
50 ArgvArgPtr *argv; // array for list of pointers
51 int argn; // count of elements in argv
52 bool mSet; // params have been passed in
53 };
54
55 class ExecCLITool
56 {
57 public:
58 ExecCLITool();
59 ~ExecCLITool();
60
61 int run(const char *toolPath, const char *toolEnvVar, ...);
62 void input(const char *data,unsigned int length);
63 void input(CFStringRef theString, bool appendNULL=false);
64 const char * data() const { return dataRead; }
65 unsigned int length() const { return dataLength; }
66
67 protected:
68
69 void child(const char *toolPath, const char *toolEnvVar, VAArgList& arglist);
70 void parent(pid_t pid);
71 void parentReadOutput();
72 void parentWriteInput();
73 void closeAllPipes();
74 void initialize();
75 void reset();
76
77 int stdoutpipe[2]; // for reading data from child into parent (child uses stdout)
78 int stdinpipe [2]; // for writing data from parent to child (child uses stdin)
79
80 char *dataRead;
81 unsigned int dataLength;
82
83 char *dataToWrite;
84 unsigned int dataToWriteLength;
85
86 static const unsigned int kReadBufSize = 1024;
87
88 };
89
90
91 #endif //_H_EXECCLITOOL
92
93