home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / C_ARCHI1.TAR / archie / pfs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-19  |  13.5 KB  |  368 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  *
  7.  * v1.2.0 - 11/19/91 (mmt) - added MSDOS & OS2 stuff
  8.  * v1.1.2 - 08/30/91 (bpk) - added VMS support
  9.  * v1.1.1 - 08/20/91 (bpk) - 4.2 -> 4.2B
  10.  */
  11.  
  12. #include <copyright.h>
  13.  
  14. #ifdef VMS
  15. # include <vms.h>
  16. #else /* not VMS */
  17. # ifndef _TYPES_
  18. #  include <sys/types.h>
  19. # endif /* _TYPES_ */
  20. # ifndef IN_H
  21. #  include <netinet/in.h> 
  22. #  define IN_H
  23. # endif
  24. #endif /* VMS */
  25.  
  26. #ifndef NULL
  27. # if defined(MSDOS)
  28. #  include <stdio.h>
  29. # else
  30. #  define NULL 0
  31. # endif /* MSDOS */
  32. #endif /* NULL */
  33.  
  34. #define        PFS_RELEASE    "Beta.4.2D"
  35. /* moved up for vdir_init */
  36. #define ZERO(p)        bzero((char *)(p), sizeof(*(p)))
  37.  
  38. /* General Definitions */
  39.  
  40. #define        MAX_PTXT_LEN    1250     /* Max length of PTEXT structure   */
  41. #define        MAX_PTXT_HDR    32       /* Max offset for start            */
  42. #define        P_ERR_STRING_SZ 100     /* Size of error string        */
  43. #define        MAX_VPATH    1024     /* Max length of virtual pathname  */
  44.  
  45. /* Definition of text structure used to pass text around */
  46.  
  47. struct ptext {
  48.     int            length;          /* Length of text (from start)    */
  49.     char        *start;          /* Start of text            */
  50.     char        dat[MAX_PTXT_LEN+2*MAX_PTXT_HDR];/* The data itself */
  51.     unsigned long     mbz;          /* ZERO to catch runaway strings  */
  52.     struct ptext    *previous;        /* Previous element in list       */
  53.     struct ptext    *next;          /* Next element in linked list    */
  54.     int            seq;          /* Sequence Number            */
  55. };
  56.  
  57. typedef struct ptext *PTEXT;
  58. typedef struct ptext PTEXT_ST;
  59.  
  60. /* Request structure: maintains information about server requests */
  61. struct preq {
  62.     int            cid;          /* Connection ID                  */
  63.     short        priority;      /* Connection priority            */
  64.     int            pf_priority;      /* Priority assigned by pri_func  */
  65.     int            recv_tot;      /* Total # of packets received    */
  66.     int            trns_tot;      /* Total # of packets to transmit */
  67.     struct ptext    *cpkt;          /* Current packet being filled in */
  68.     struct ptext    *recv;          /* Received packets               */
  69.     struct ptext    *trns;          /* Transmitted packets            */
  70.     int            rcvd_thru;      /* Received all packets through # */
  71.     struct preq        *previous;        /* Previous element in list       */
  72.     struct preq        *next;          /* Next element in linked list    */
  73.     struct sockaddr_in    fromto;       /* Sender/Destination            */
  74. };
  75.  
  76. typedef struct preq *PREQ;
  77. typedef struct preq PREQ_ST;
  78.  
  79.  
  80. /* Definition of structure containing information on virtual link */
  81.  
  82. struct vlink {
  83.     int            dontfree;      /* Flag: don't free this link     */
  84.     char        *name;          /* Component of path name        */
  85.     char        linktype;      /* L = Link, U = Union, N= Native */
  86.     int            expanded;      /* Has a union link been expanded */
  87.     char        *type;            /* Type of object pointed to      */
  88.     struct vlink    *filters;      /* Filters associated with link   */
  89.     struct vlink    *replicas;      /* Replicas (* see comment below) */
  90.     char        *hosttype;      /* Type of hostname            */
  91.     char        *host;          /* Files physical location        */
  92.     char        *nametype;      /* Type of filename            */
  93.     char        *filename;      /* System level filename        */
  94.     long        version;      /* Version number of destination  */
  95.     long        f_magic_no;      /* File's magic number        */
  96.     struct acl        *acl;          /* ACL for link            */
  97.     long        dest_exp;      /* Expiration for dest of link    */
  98.     long        link_exp;      /* Expiration of link itself      */
  99.     char        *args;          /* Arguments if this is a filter  */
  100.     struct pattrib    *lattrib;      /* Attributes associated w/ link  */
  101.     struct pfile    *f_info;      /* Info to be assoicated w/ file  */
  102.     struct vlink    *previous;        /* Previous elt in linked list    */
  103.     struct vlink    *next;          /* Next element in linked list    */
  104. };
  105.  
  106. typedef struct vlink *VLINK;
  107. typedef struct vlink VLINK_ST;
  108.  
  109. /* * Note that vlink->replicas is not really a list of replicas of the  */
  110. /*   object.  Instead, it is a list of the objects returned during name */
  111. /*   resolution that share the same name as the current object.  Such   */
  112. /*   an object should only be considered a replica if it also shares    */
  113. /*   the same non-zero magic number.                                    */
  114.  
  115. /* Definition of structure continiaing virtual directory information    */
  116.  
  117. struct vdir {
  118.     int            version;      /* Version of local directory fmt  */
  119.     int            inc_native;      /* Include the native directory    */
  120.     long        magic_no;      /* Magic number of current file    */
  121.     struct acl        *dacl;            /* Default acl for links in dir    */
  122.     struct pfile    *f_info;      /* Directory file info             */
  123.     struct vlink    *links;          /* The directory entries         */
  124.     struct vlink    *lastlink;      /* Last directory entry            */
  125.     struct vlink    *ulinks;      /* The entries for union links     */
  126.     struct vdir        *previous;        /* Previous element in linked list */
  127.     struct vdir        *next;          /* Next element in linked list     */
  128. };
  129.  
  130. typedef struct vdir *VDIR;
  131. typedef struct vdir VDIR_ST;
  132.  
  133. /* Initialize directory */
  134. #define vdir_init(dir)  ZERO(dir)
  135. /* XXX: was
  136.  
  137.   dir->version = 0;     dir->inc_native = 0; \
  138.   dir->magic_no = 0;    dir->f_info = NULL; \
  139.   dir->links = NULL;    dir->lastlink = NULL; \
  140.   dir->ulinks = NULL;   dir->dacl = NULL; \
  141.   dir->previous = NULL; dir->next = NULL;
  142. */
  143.  
  144. #define vdir_copy(d1,d2) d2->version = d1->version; \
  145.                          d2->inc_native = d1->inc_native; \
  146.                          d2->magic_no = d1->magic_no; \
  147.                  d2->f_info = d1->f_info; \
  148.                          d2->links = d1->links; \
  149.                          d2->lastlink = d1->lastlink; \
  150.                          d2->ulinks = d1->ulinks; \
  151.                          d2->dacl = d1->dacl; \
  152.                          d2->previous = d1->previous; \
  153.                          d2->next = d1->next; 
  154.                          
  155. /* Values of ->inc_native in vdir structure */
  156. #define VDIN_REALONLY    -1   /* Include native files, but not . and ..       */
  157. #define VDIN_NONATIVE     0   /* Do not include files from native directory   */
  158. #define VDIN_INCLNATIVE     1   /* Include files from native directory          */
  159. #define VDIN_NATIVEONLY  2   /* All entries in directory are from native dir */
  160. #define VDIN_PSEUDO      3   /* Directory is not real                        */
  161.  
  162.  
  163. /* Definition of structure containing information on a specific file */
  164.  
  165. union avalue {
  166.     char        *ascii;        /* Character string                */
  167.     struct vlink    *link;        /* A link               */
  168. };
  169.  
  170.  
  171. struct pattrib {
  172.     char        precedence;    /* Precedence for link attribute   */
  173.     char        *aname;        /* Name of the attribute           */
  174.     char        *avtype;    /* Type of the attribute value     */
  175.     union avalue    value;        /* Attribute Value                 */
  176.     struct pattrib    *previous;      /* Previous element in linked list */
  177.     struct pattrib    *next;        /* Next element in linked list     */
  178. };
  179.  
  180. typedef struct pattrib *PATTRIB;
  181. typedef struct pattrib PATTRIB_ST;
  182.  
  183. #define     ATR_PREC_OBJECT  'O'   /* Authoritative answer for object */
  184. #define     ATR_PREC_LINK    'L'   /* Authoritative answer for link   */
  185. #define     ATR_PREC_CACHED  'C'   /* Object info cached w/ link      */
  186. #define     ATR_PREC_REPLACE 'R'   /* From link (replaces O)          */
  187. #define     ATR_PREC_ADD     'A'   /* From link (additional value)    */
  188.  
  189. /* **** Incomplete **** */
  190. struct pfile {
  191.     int            version;      /* Version of local finfo format   */
  192.     long        f_magic_no;      /* Magic number of current file    */
  193.     long        exp;          /* Expiration date of timeout      */
  194.     long        ttl;          /* Time to live after reference    */
  195.     long        last_ref;      /* Time of last reference          */
  196.     struct vlink    *forward;      /* List of forwarding pointers     */
  197.     struct vlink    *backlinks;      /* Partial list of back links      */
  198.     struct pattrib    *attributes;      /* List of file attributes         */
  199.     struct pfile    *previous;        /* Previous element in linked list */
  200.     struct pfile    *next;          /* Next element in linked list     */
  201. };
  202.  
  203. typedef struct pfile *PFILE;
  204. typedef struct pfile PFILE_ST;
  205.  
  206. /* Definition of structure contining an access control list entry */
  207.  
  208. struct acl {
  209.     int            acetype;      /* Access Contol Entry type       */
  210.     char        *atype;           /* Authentication type            */
  211.     char        *rights;          /* Rights                         */
  212.     char        *principals;      /* Authorized principals          */
  213.     struct restrict     *restrictions;    /* Restrictions on use            */
  214.     struct acl        *previous;        /* Previous elt in linked list    */
  215.     struct acl        *next;          /* Next element in linked list    */
  216. };
  217. typedef struct acl *ACL;
  218. typedef struct acl ACL_ST;
  219.  
  220. #define ACL_NONE        0         /* Nobody authorized by ths entry */
  221. #define ACL_DEFAULT        1         /* System default                 */
  222. #define ACL_SYSTEM        2         /* System administrator           */
  223. #define ACL_OWNER               3         /* Directory owner                */
  224. #define ACL_DIRECTORY           4         /* Same as directory              */
  225. #define ACL_ANY                 5         /* Any user                       */
  226. #define ACL_AUTHENT             6         /* Authenticated principal        */
  227. #define ACL_LGROUP              7         /* Local group                    */
  228. #define ACL_GROUP               8         /* External group                 */
  229. #define ACL_ASRTHOST            10        /* Check host and asserted userid */
  230. #define ACL_TRSTHOST            11        /* ASRTHOST from privileged port  */
  231.  
  232.  
  233. /* Definition of structure contining access restrictions */
  234. /* for future extensions                                 */
  235. struct restrict {
  236.     struct acl        *previous;        /* Previous elt in linked list    */
  237.     struct acl        *next;          /* Next element in linked list    */
  238. };
  239.  
  240. /* Definitions for send_to_dirsrv */
  241. #define    CLIENT_DIRSRV_TIMEOUT        4    /* time between retries      */
  242. #define CLIENT_DIRSRV_BACKOFF(x)  (2 * x)    /* Backoff algorithm         */
  243. #define CLIENT_DIRSRV_RETRY        3    /* retry this many times     */
  244.  
  245. /* Definitions for rd_vlink and rd_vdir */
  246. #define        SYMLINK_NESTING 10       /* Max nesting depth for sym links */
  247.  
  248. /* Definition fo check_acl */
  249. #define        ACL_NESTING     10       /* Max depth for ACL group nesting */
  250.  
  251. /* Flags for mk_vdir */
  252. #define         MKVD_LPRIV     1   /* Minimize privs for creator in new ACL    */
  253.  
  254. /* Flags for get_vdir */
  255. #define         GVD_UNION      0    /* Do not expand union links              */
  256. #define      GVD_EXPAND     1   /* Expand union links locally             */
  257. #define         GVD_LREMEXP    3   /* Request remote expansion of local links   */
  258. #define         GVD_REMEXP     7   /* Request remote expansion of all links     */
  259. #define         GVD_VERIFY     8    /* Only verify args are for a directory      */
  260. #define      GVD_FIND       16   /* Stop expanding when match is found        */
  261. #define         GVD_ATTRIB    32   /* Request attributes from remote server     */
  262. #define         GVD_NOSORT       64   /* Do not sort links when adding to dir      */
  263.  
  264. /* Flags for rd_vdir */
  265. #define         RVD_UNION      GVD_UNION
  266. #define         RVD_EXPAND     GVD_EXPAND 
  267. #define         RVD_LREMEXP    GVD_LREMEXP
  268. #define         RVD_REMEXP     GVD_REMEXP
  269. #define         RVD_DFILE_ONLY GVD_VERIFY /* Only return ptr to dir file        */
  270. #define      RVD_FIND       GVD_FIND   
  271. #define      RVD_ATTRIB     GVD_ATTRIB
  272. #define         RVD_NOSORT        GVD_NOSORT
  273. #define         RVD_NOCACHE    128
  274.  
  275. /* Flags for add_vlink */
  276. #define         AVL_UNION      1   /* Link is a union link                      */
  277.  
  278. /* Flags for vl_insert */
  279. #define         VLI_NOCONFLICT 0   /* Do not insert links w/ conflicting names  */
  280. #define      VLI_ALLOW_CONF 1   /* Allow links with conflicting names        */
  281. #define         VLI_NOSORT     2   /* Allow conflicts and don't sort            */
  282.  
  283. /* Flags for mapname */
  284. #define      MAP_READWRITE  0   /* Named file to be read and written         */
  285. #define         MAP_READONLY   1   /* Named file to be read only                */
  286.  
  287. /* Flags for modify_acl */
  288. #define         MACL_NOSYSTEM   0x01
  289. #define      MACL_NOSELF     0x02
  290. #define      MACL_DEFAULT    0x08
  291. #define      MACL_SET        0x0C
  292. #define      MACL_INSERT     0x14
  293. #define      MACL_DELETE     0x10
  294. #define      MACL_ADD        0x1C
  295. #define      MACL_SUBTRACT   0x18
  296. #define      MACL_LINK       0x00
  297. #define      MACL_DIRECTORY  0x20
  298. #define      MACL_OBJECT     0x60
  299. #define      MACL_INCLUDE    0x40
  300.  
  301. #define      MACL_OP    (MACL_DEFAULT|MACL_SET|MACL_INSERT|\
  302.              MACL_DELETE|MACL_ADD|MACL_SUBTRACT)
  303.  
  304. #define      MACL_OTYPE (MACL_LINK|MACL_DIRECTORY|MACL_OBJECT|MACL_INCLUDE)
  305.  
  306. /* Access methods returned by Pget_am */
  307. #define P_AM_ERROR            0
  308. #define P_AM_FTP            1
  309. #define P_AM_AFTP            2  /* Anonymous FTP  */
  310. #define P_AM_NFS            4
  311. #define P_AM_KNFS            8  /* Kerberized NFS */
  312. #define P_AM_AFS               16
  313.  
  314. /* Return codes */
  315.  
  316. #define        PSUCCESS    0
  317. #define        PFAILURE    255
  318.  
  319. /* Hush up warnings.  */
  320. void vllfree();
  321.  
  322. /* Procedures in libpfs.a */
  323.  
  324. char *pget_wdhost(), *pget_wdfile(), *pget_wd(), *pget_hdhost();
  325. char *pget_hdfile(), *pget_hd(), *pget_rdhost(), *pget_rdfile();
  326. char *pget_dhost(), *pget_dfile(), *pget_vsname(), *nlsindex();
  327. char *sindex(), *strtok(), *nxtline(), *unquote(), *stcopy();
  328. char *stcopyr(), *readheader(), *month_sname();
  329.  
  330. long        asntotime();
  331.  
  332. PTEXT        ptalloc();
  333. PTEXT        dirsend();
  334.  
  335. PREQ        pralloc();
  336. PREQ        get_next_request();
  337.  
  338. VLINK        rd_slink();
  339. VLINK        rd_vlink();
  340. VLINK        vl_delete();
  341. VLINK        vlalloc();
  342. VLINK        vlcopy();
  343.  
  344. PFILE        pfalloc();
  345.  
  346. PATTRIB         parse_attribute();
  347. PATTRIB         atalloc();
  348. PATTRIB     pget_at();
  349.  
  350. ACL             acalloc();
  351. ACL             get_acl();
  352.  
  353. /* Miscellaneous useful definitions */
  354. #ifndef TRUE
  355. #define TRUE        1
  356. #define FALSE        0
  357. #endif
  358.  
  359. #define AUTHORIZED      1
  360. #define NOT_AUTHORIZED  0
  361. #define NEG_AUTHORIZED  -1
  362.  
  363. #ifndef NULL
  364. #define NULL        0
  365. #endif
  366.  
  367. #define FAILED        -1
  368.