1 #ifndef INSTALL_H
2 #define INSTALL_H
3 
4 #include <errno.h>
5 
6 #define INSTALL_NO_FLAGS 0x0000u
7 #define INSTALL_DRYRUN   0x0001u
8 
9 enum install_op_t {
10   INST_COPY       = 0,
11   INST_COPY_EXEC  = 1,
12   INST_SYMLINK    = 2,
13   INST_MKDIR      = 3,
14   INST_LIBLINK    = 4
15 };
16 
17 enum install_status_enum_t {
18   INSTALL_STATUS_OK    = 0,
19   INSTALL_STATUS_ERROR = 1,
20   INSTALL_STATUS_FATAL = 2
21 };
22 
23 struct install_status_t {
24   enum install_status_enum_t status;
25   /*@dependent@*/ /*@null@*/ const char *message;
26   /*@dependent@*/ /*@null@*/ const char *error_message;
27 };
28 
29 #define INSTALL_STATUS_INIT {INSTALL_STATUS_FATAL,0,0}
30 
31 struct install_item {
32   enum install_op_t op;
33   /*@dependent@*/ char *src;
34   /*@dependent@*/ char *dst;
35   /*@dependent@*/ char *dir;
36   /*@dependent@*/ char *owner;
37   /*@dependent@*/ char *group;
38   int perm;
39 };
40 
41 struct install_status_t install_init (const char *);
42 struct install_status_t install (struct install_item *, unsigned int);
43 struct install_status_t install_check (struct install_item *);
44 struct install_status_t deinstall (struct install_item *, unsigned int);
45 
46 void install_callback_warn_set (void (*)(const char *, void *));
47 void install_callback_info_set (void (*)(const char *, void *));
48 void install_callback_data_set (void *);
49 
50 void install_fake_root (const char *);
51 
52 const char *install_error (int);
53 extern struct install_item insthier[];
54 extern unsigned long insthier_len;
55 extern unsigned long install_failed;
56 
57 #ifdef INSTALL_IMPLEMENTATION
58 
59 #define INSTALL_MAX_PATHLEN      (size_t) 1024
60 #define INSTALL_MAX_MSGLEN       (size_t) 8192
61 #define INSTALL_NULL_USER_NAME   ":"
62 #define INSTALL_NULL_GROUP_NAME  ":"
63 #define INSTALL_NULL_PERMISSIONS {0}
64 
65 typedef struct {
66   unsigned int value;
67 } permissions_t;
68 
69 typedef struct {
70   unsigned long value;
71 } error_t;
72 
73 enum install_file_type_t {
74   INSTALL_FILE_TYPE_FILE,
75   INSTALL_FILE_TYPE_CHARACTER_SPECIAL,
76   INSTALL_FILE_TYPE_DIRECTORY,
77   INSTALL_FILE_TYPE_SYMLINK,
78   INSTALL_FILE_TYPE_SOCKET,
79   INSTALL_FILE_TYPE_FIFO
80 };
81 
82 extern char inst_exec_suffix [16];
83 extern char inst_dlib_suffix [16];
84 
85 extern void (*install_callback_warn)(const char *, void *);
86 extern void (*install_callback_info)(const char *, void *);
87 extern void  *install_callback_data;
88 
89 void install_permissions_assign (permissions_t *, int);
90 int  install_permissions_compare (permissions_t, permissions_t);
91 
92 unsigned int install_umask (unsigned int);
93 
94 int install_file_type (const char *, enum install_file_type_t *, int);
95 int install_file_type_lookup (const char *, enum install_file_type_t *);
96 int install_file_type_name_lookup (enum install_file_type_t, /*@dependent@*/ const char **);
97 
98 #include "install_os.h"
99 
100 void install_status_assign (struct install_status_t *, enum install_status_enum_t, /*@null@*/ /*@dependent@*/ const char *);
101 struct install_status_t install_file_copy (const char *, const char *, user_id_t, group_id_t, permissions_t);
102 
103 struct install_platform_callbacks_t {
104   struct install_status_t (*init) (void);
105 
106   const char * (*error_message) (error_t);
107   const char * (*error_message_current) (void);
108   error_t      (*error_current) (void);
109   void         (*error_reset) (void);
110 
111   int          (*gid_compare) (group_id_t, group_id_t);
112   unsigned int (*gid_format) (char *, group_id_t);
113   unsigned int (*gid_scan) (const char *, group_id_t *);
114   int          (*gid_current) (group_id_t *);
115   int          (*gid_lookup) (const char *, group_id_t *);
116   int          (*gid_valid) (group_id_t);
117   void         (*gid_free) (group_id_t *);
118 
119   int          (*uid_compare) (user_id_t,  user_id_t);
120   unsigned int (*uid_format) (char *, user_id_t);
121   unsigned int (*uid_scan) (const char *, user_id_t *);
122   int          (*uid_current) (user_id_t *);
123   int          (*uid_lookup) (const char *, user_id_t *);
124   int          (*uid_valid) (user_id_t);
125   void         (*uid_free) (user_id_t *);
126 
127   const char * (*user_name_current) (void);
128 
129   int          (*make_dir) (const char *, permissions_t);
130 
131   int          (*file_mode_get) (const char *, permissions_t *);
132   int          (*file_mode_set) (const char *file, permissions_t mode);
133   int          (*file_ownership_get) (const char *, user_id_t *, group_id_t *);
134   int          (*file_ownership_set) (const char *, user_id_t, group_id_t);
135   int          (*file_size) (const char *, size_t *);
136   int          (*file_link) (const char *, const char *);
137 
138   int          (*can_set_ownership) (user_id_t);
139   int          (*supports_symlinks) (void);
140   int          (*supports_posix_modes) (void);
141   unsigned int (*umask) (unsigned int);
142 };
143 
144 extern const struct install_platform_callbacks_t install_platform_posix;
145 extern const struct install_platform_callbacks_t install_platform_win32;
146 
147 #endif /* INSTALL_IMPLEMENTATION */
148 
149 #endif /* INSTALL_H */
150