1 /*
2  * Copyright (c) 1990,1993 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5 
6 #ifndef AFPD_GLOBALS_H
7 #define AFPD_GLOBALS_H 1
8 
9 #include <sys/param.h>
10 #include <grp.h>
11 #include <sys/types.h>
12 #include <stdbool.h>
13 
14 #ifdef HAVE_NETDB_H
15 #include <netdb.h>  /* this isn't header-protected under ultrix */
16 #endif /* HAVE_NETDB_H */
17 
18 #include <atalk/afp.h>
19 #include <atalk/compat.h>
20 #include <atalk/unicode.h>
21 #include <atalk/uam.h>
22 #include <atalk/iniparser.h>
23 #ifdef WITH_DTRACE
24 #include <atalk/afp_dtrace.h>
25 #else
26 /* List of empty dtrace macros */
27 #define AFP_AFPFUNC_START(a,b)
28 #define AFP_AFPFUNC_DONE(a, b)
29 #define AFP_CNID_START(a)
30 #define AFP_CNID_DONE()
31 #define AFP_READ_START(a)
32 #define AFP_READ_DONE()
33 #define AFP_WRITE_START(a)
34 #define AFP_WRITE_DONE()
35 #endif
36 
37 /* #define DOSFILELEN 12 */             /* Type1, DOS-compat*/
38 #define MACFILELEN 31                   /* Type2, HFS-compat */
39 #define UTF8FILELEN_EARLY 255           /* Type3, early Mac OS X 10.0-10.4.? */
40 /* #define UTF8FILELEN_NAME_MAX 765 */  /* Type3, 10.4.?- , getconf NAME_MAX */
41 /* #define UTF8FILELEN_SPEC 0xFFFF */   /* Type3, spec on document */
42 /* #define HFSPLUSFILELEN 510 */        /* HFS+ spec, 510byte = 255codepoint */
43 
44 #define MAXUSERLEN 256
45 
46 #define DEFAULT_MAX_DIRCACHE_SIZE 8192
47 
48 #define OPTION_DEBUG         (1 << 0)
49 #define OPTION_CLOSEVOL      (1 << 1)
50 #define OPTION_SERVERNOTIF   (1 << 2)
51 #define OPTION_NOSENDFILE    (1 << 3)
52 #define OPTION_VETOMSG       (1 << 4) /* whether to send an AFP message for veto file access */
53 #define OPTION_AFP_READ_LOCK (1 << 5) /* whether to do AFP spec conforming read locks (default: no) */
54 #define OPTION_ANNOUNCESSH   (1 << 6)
55 #define OPTION_UUID          (1 << 7)
56 #define OPTION_ACL2MACCESS   (1 << 8)
57 #define OPTION_NOZEROCONF    (1 << 9)
58 #define OPTION_ACL2MODE      (1 << 10)
59 #define OPTION_SHARE_RESERV  (1 << 11) /* whether to use Solaris fcntl F_SHARE locks */
60 #define OPTION_DBUS_AFPSTATS (1 << 12) /* whether to run dbus thread for afpstats */
61 #define OPTION_SPOTLIGHT     (1 << 13) /* whether to initialize Spotlight support */
62 #define OPTION_SPOTLIGHT_VOL (1 << 14) /* whether spotlight shall be enabled by default for volumes */
63 #define OPTION_RECVFILE      (1 << 15)
64 #define OPTION_SPOTLIGHT_EXPR (1 << 16) /* whether to allow Spotlight logic expressions */
65 
66 #define PASSWD_NONE     0
67 #define PASSWD_SET     (1 << 0)
68 #define PASSWD_NOSAVE  (1 << 1)
69 #define PASSWD_ALL     (PASSWD_SET | PASSWD_NOSAVE)
70 
71 #define IS_AFP_SESSION(obj) ((obj)->dsi && (obj)->dsi->serversock == -1)
72 
73 /**********************************************************************************************
74  * Ini config sections
75  **********************************************************************************************/
76 
77 #define INISEC_GLOBAL "Global"
78 #define INISEC_HOMES  "Homes"
79 
80 struct DSI;
81 #define AFPOBJ_TMPSIZ (MAXPATHLEN)
82 
83 struct afp_volume_name {
84     time_t     mtime;
85     int        loaded;
86 };
87 
88 struct afp_options {
89     int connections;            /* Maximum number of possible AFP connections */
90     int tickleval;
91     int timeout;
92     int flags;
93     int dircachesize;
94     int sleep;                  /* Maximum time allowed to sleep (in tickles) */
95     int disconnected;           /* Maximum time in disconnected state (in tickles) */
96     int fce_fmodwait;           /* number of seconds FCE file mod events are put on hold */
97     unsigned int tcp_sndbuf, tcp_rcvbuf;
98     unsigned char passwdbits, passwdminlen;
99     uint32_t server_quantum;
100     int dsireadbuf; /* scale factor for sizefof(dsi->buffer) = server_quantum * dsireadbuf */
101     char *hostname;
102     char *listen, *interfaces, *port;
103     char *Cnid_srv, *Cnid_port;
104     char *configfile;
105     char *uampath, *fqdn;
106     char *sigconffile;
107     char *uuidconf;
108     char *guest, *loginmesg, *keyfile, *passwdfile, *extmapfile;
109     char *uamlist;
110     char *signatureopt;
111     unsigned char signature[16];
112     char *k5service, *k5realm, *k5keytab;
113     size_t k5principal_buflen;
114     char *k5principal;
115     char *unixcodepage, *maccodepage, *volcodepage;
116     charset_t maccharset, unixcharset;
117     mode_t umask;
118     mode_t save_mask;
119     gid_t admingid;
120     bool force_user;
121     uid_t force_uid;
122     bool force_group;
123     gid_t force_gid;
124     int    volnamelen;
125     /* default value for winbind authentication */
126     char *ntdomain, *ntseparator, *addomain;
127     char *logconfig;
128     char *logfile;
129     char *mimicmodel;
130     char *zeroconfname;
131     char *adminauthuser;
132     char *ignored_attr;
133     int  splice_size;
134     char *cnid_mysql_host;
135     char *cnid_mysql_user;
136     char *cnid_mysql_pw;
137     char *cnid_mysql_db;
138     struct afp_volume_name volfile;
139     struct afp_volume_name includefile;
140     uint64_t sparql_limit;
141 };
142 
143 typedef struct AFPObj {
144     const char *cmdlineconfigfile;
145     int cmdlineflags;
146     const void *signature;
147     struct DSI *dsi;
148     struct afp_options options;
149     dictionary *iniconfig;
150     char username[MAXUSERLEN];
151     /* to prevent confusion, only use these in afp_* calls */
152     char oldtmp[AFPOBJ_TMPSIZ + 1], newtmp[AFPOBJ_TMPSIZ + 1];
153     void *uam_cookie; /* cookie for uams */
154     struct session_info  sinfo;
155     uid_t uid;  /* client login user id */
156     uid_t euid; /* client effective process user id */
157     int ipc_fd; /* anonymous PF_UNIX socket for IPC with afpd parent */
158     gid_t *groups;
159     int ngroups;
160     int afp_version;
161     int cnx_cnt, cnx_max;
162     /* Functions */
163     void (*logout)(void);
164     void (*exit)(int);
165     int (*reply)(void *, int);
166     int (*attention)(void *, AFPUserBytes);
167     int fce_version;
168     char *fce_ign_names;
169     char *fce_notify_script;
170     struct sl_ctx *sl_ctx;
171 } AFPObj;
172 
173 /* typedef for AFP functions handlers */
174 typedef int (*AFPCmd)(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
175 
176 /* Global variables */
177 extern AFPObj             *AFPobj;
178 extern int                afp_version;
179 extern int                afp_errno;
180 extern unsigned char      nologin;
181 extern struct dir         *curdir;
182 extern char               getwdbuf[];
183 extern struct afp_options default_options;
184 extern const char         *Cnid_srv;
185 extern const char         *Cnid_port;
186 
187 extern int  get_afp_errno   (const int param);
188 extern void afp_options_init (struct afp_options *);
189 extern void afp_options_parse_cmdline(AFPObj *obj, int ac, char **av);
190 extern int setmessage (const char *);
191 extern void readmessage (AFPObj *);
192 
193 /* afp_util.c */
194 extern const char *AfpNum2name (int );
195 extern const char *AfpErr2name(int err);
196 
197 /* directory.c */
198 extern struct dir rootParent;
199 
200 extern void afp_over_dsi (AFPObj *);
201 extern void afp_over_dsi_sighandlers(AFPObj *obj);
202 #endif /* globals.h */
203