|
|
1.1 root 1: /* support.c - remote distribution -- support routines */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/others/idist/RCS/support.c,v 7.0 89/11/23 21:58:44 mrose Rel $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/others/idist/RCS/support.c,v 7.0 89/11/23 21:58:44 mrose Rel $
9: *
10: * Support routines required by both client and server.
11: *
12: * Julian Onions <[email protected]>
13: * Nottingham University Computer Science.
14: *
15: *
16: * $Log: support.c,v $
17: * Revision 7.0 89/11/23 21:58:44 mrose
18: * Release 6.0
19: *
20: */
21:
22: #include <stdio.h>
23: #include "Idist-ops.h" /* operation definitions */
24: #include "Idist-types.h" /* type definitions */
25: #include "defs.h"
26:
27: struct type_Idist_FileSpec *
28: makefs (type, opts, mode, size, mtime, uname, group, name, lname)
29: unsigned short type, mode;
30: off_t size;
31: time_t mtime;
32: int opts;
33: char *uname, *group, *name, *lname;
34: {
35: struct type_Idist_FileSpec *fs;
36: struct type_Idist_FileType *makeftype ();
37: struct type_Idist_FileTime *makefmtime ();
38: struct type_Idist_Options *makeopts ();
39:
40: if ((fs = (struct type_Idist_FileSpec *) malloc (sizeof *fs)) == NULL)
41: adios ("memory", "out of");
42: fs -> filetype = makeftype (type);
43: fs -> fileopts = makeopts (opts);
44: fs -> filemode = mode;
45: fs -> filesize = size;
46: fs -> filemtime = makefmtime (mtime);
47: fs -> fileowner = str2qb (uname, strlen(uname), 1);
48: fs -> filegroup = str2qb (group, strlen(group), 1);
49: fs -> filename = str2qb (name, strlen(name), 1);
50: fs -> linkname = str2qb (lname, strlen (lname), 1);
51: return fs;
52: }
53:
54: struct type_Idist_Options *makeopts (opts)
55: int opts;
56: {
57: struct type_Idist_Options *rdo;
58:
59: rdo = pe_alloc (PE_CLASS_UNIV, PE_FORM_PRIM, PE_PRIM_BITS);
60: if (rdo == NULL)
61: adios ("memory", "out of");
62: #define dobit(X,Y) if (opts & (X)) (void) bit_on (rdo, (Y))
63: dobit (VERIFY, bit_Idist_Options_verify);
64: dobit (WHOLE, bit_Idist_Options_whole);
65: dobit (YOUNGER, bit_Idist_Options_younger);
66: dobit (COMPARE, bit_Idist_Options_compare);
67: dobit (FOLLOW, bit_Idist_Options_follow);
68: dobit (IGNLNKS, bit_Idist_Options_ignlinks);
69: #ifdef UW
70: dobit (NOINSTALL, bit_Idist_Options_noinstall);
71: #endif
72: #undef dobit
73: return rdo;
74: }
75:
76: struct type_Idist_FileType *makeftype (type)
77: unsigned short type;
78: {
79: struct type_Idist_FileType *ft;
80:
81: if ((ft = (struct type_Idist_FileType *) malloc (sizeof *ft)) == NULL)
82: adios ("memory", "out of");
83: switch (type) {
84: case S_IFDIR:
85: ft -> parm = int_Idist_FileType_directory;
86: break;
87: case S_IFLNK:
88: ft -> parm = int_Idist_FileType_symlink;
89: break;
90: case S_IFREG:
91: ft -> parm = int_Idist_FileType_regular;
92: break;
93: case 0:
94: ft -> parm = int_Idist_FileType_hardlink;
95: break;
96: default:
97: adios (NULLCP, "Illegal file type (%d)", type);
98: break;
99: }
100: return ft;
101: }
102:
103: struct type_Idist_FileTime *makefmtime (mtime)
104: long mtime;
105: {
106: struct type_Idist_FileTime *fm;
107:
108: if ((fm = (struct type_Idist_FileTime *) malloc (sizeof *fm)) == NULL)
109: adios ("memory", "out of");
110: /* Convert to time since Jan 1 1900 */
111: fm -> parm = mtime + 2208988800L;
112: return fm;
113: }
114:
115: long convtime (fm)
116: struct type_Idist_FileTime *fm;
117: {
118: return fm -> parm - 2208988800L;
119: }
120:
121: /*
122: * Expand file names beginning with `~' into the
123: * user's home directory path name. Return a pointer in buf to the
124: * part corresponding to `file'.
125: */
126: char *
127: exptilde(buf, file)
128: char buf[];
129: register char *file;
130: {
131: register char *s1, *s2, *s3;
132: extern char homedir[];
133:
134: if (*file != '~') {
135: (void) strcpy(buf, file);
136: return(buf);
137: }
138: if (*++file == '\0') {
139: s2 = homedir;
140: s3 = NULL;
141: } else if (*file == '/') {
142: s2 = homedir;
143: s3 = file;
144: } else {
145: s3 = file;
146: while (*s3 && *s3 != '/')
147: s3++;
148: if (*s3 == '/')
149: *s3 = '\0';
150: else
151: s3 = NULL;
152: if (pw == NULL || strcmp(pw->pw_name, file) != 0) {
153: if ((pw = getpwnam(file)) == NULL) {
154: if (s3 != NULL)
155: *s3 = '/';
156: return(NULL);
157: }
158: }
159: if (s3 != NULL)
160: *s3 = '/';
161: s2 = pw->pw_dir;
162: }
163: for (s1 = buf; *s1++ = *s2++; )
164: ;
165: s2 = --s1;
166: if (s3 != NULL) {
167: s2++;
168: while (*s1++ = *s3++)
169: ;
170: }
171: return(s2);
172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.