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