|
|
1.1 root 1: /* add.c - */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/add.c,v 7.2 90/07/09 14:46:56 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/quipu/dish/RCS/add.c,v 7.2 90/07/09 14:46:56 mrose Exp $
9: *
10: *
11: * $Log: add.c,v $
12: * Revision 7.2 90/07/09 14:46:56 mrose
13: * sync
14: *
15: * Revision 7.1 90/01/11 18:37:30 mrose
16: * real-sync
17: *
18: * Revision 7.0 89/11/23 22:19:55 mrose
19: * Release 6.0
20: *
21: */
22:
23: /*
24: * NOTICE
25: *
26: * Acquisition, use, and distribution of this module and related
27: * materials are subject to the restrictions of a license agreement.
28: * Consult the Preface in the User's Manual for the full terms of
29: * this agreement.
30: *
31: */
32:
33:
34: #include "quipu/util.h"
35: #include "quipu/dua.h"
36: #include "quipu/add.h"
37: #include "quipu/entry.h"
38:
39: #define ORG_PERSON "thornPerson & quipuObject"
40: /* this should probably go elsewhere !!! */
41:
42: extern DN dn;
43:
44: #define OPT (!frompipe || rps -> ps_byteno == 0 ? opt : rps)
45: #define RPS (!frompipe || opt -> ps_byteno == 0 ? rps : opt)
46: extern char frompipe;
47: extern PS opt, rps;
48:
49: char fname[128];
50: static char new_draft;
51:
52: call_add (argc, argv)
53: int argc;
54: char **argv;
55: {
56:
57: Entry entry_ptr;
58: FILE *fd;
59: struct ds_addentry_arg add_arg;
60: struct DSError error;
61: Attr_Sequence get_attributes();
62: extern int parse_status;
63:
64: int x;
65: int draft_flag = 0;
66: char *O_class = NULLCP;
67: char noedit_flag = FALSE;
68: DN moddn;
69: char *home;
70:
71: if (home = getenv ("DISHDRAFT"))
72: (void) strcpy (fname, home);
73: else
74: if (home = getenv ("HOME"))
75: (void) sprintf (fname, "%s/.dishdraft", home);
76: else
77: (void) strcpy (fname, "./.dishdraft");
78: new_draft = FALSE;
79:
80: if ((argc = service_control (OPT, argc, argv, &add_arg.ada_common)) == -1)
81: return;
82:
83: for (x = 1; x < argc; x++) {
84: if (test_arg (argv[x], "-template", 1)) {
85: int i;
86: FILE *in, *out;
87: extern int errno;
88:
89: draft_flag = 1;
90: if (++x == argc) {
91: ps_printf (OPT, "template file name missing\n");
92: Usage (argv[0]);
93: return;
94: }
95: if ((in = fopen (argv[x], "r")) == NULL) {
96: ps_printf (OPT, "unable to open template %s: %s\n",
97: argv[x], sys_errname (errno));
98: return;
99: }
100: i = umask (0177);
101: out = fopen (fname, "w");
102: (void) umask (i);
103: if (out == NULL) {
104: ps_printf (OPT, "unable to write draft %s: %s\n",
105: fname, sys_errname (errno));
106: (void) fclose (in);
107: return;
108: }
109: while ((i = getc (in)) != EOF)
110: if (putc (i, out) == EOF) {
111: ps_printf (OPT, "error writing draft %s: %s\n",
112: fname, sys_errname (errno));
113: (void) fclose (in);
114: (void) fclose (out);
115: return;
116: }
117: (void) fclose (in);
118: (void) fclose (out);
119: } else if (test_arg (argv[x], "-draft", 1)) {
120: draft_flag = 1;
121: if (++x == argc) {
122: ps_printf (OPT, "Draft file name missing\n");
123: Usage (argv[0]);
124: return;
125: }
126: (void) strcpy (fname, argv[x]);
127: } else if (test_arg (argv[x], "-objectclass",1)) {
128: if (++x == argc) {
129: ps_printf (OPT, "Object Class missing\n");
130: Usage (argv[0]);
131: return;
132: }
133: O_class = argv[x];
134: } else if (test_arg(argv[x], "-newdraft", 2))
135: new_draft = TRUE;
136: else if (test_arg(argv[x], "-noedit", 3))
137: noedit_flag = TRUE;
138: else if (move (argv[x]) == OK)
139: continue;
140: else {
141: ps_printf (OPT,"Unknown option %s\n",argv[x]);
142: Usage (argv[0]);
143: return;
144: }
145: }
146:
147: if ((!noedit_flag) && (draft_flag != 1)) { /* if no draft - create a template */
148: if (add_template (fname, O_class) != OK)
149: return;
150: }
151:
152: if ( ! noedit_flag)
153: if (editentry (1, argv) != OK) {
154: make_old (fname,draft_flag);
155: return;
156: }
157:
158: /* now parse the files */
159:
160: if ((fd = fopen (fname, "r")) == (FILE *) NULL) {
161: ps_printf (OPT, "Can't open draft entry %s\n", fname);
162: return;
163: }
164:
165: entry_ptr = get_default_entry (NULLENTRY);
166: entry_ptr->e_attributes = get_attributes (fd);
167:
168: (void) fclose (fd);
169: if (parse_status != 0)
170: return ;
171:
172: add_arg.ada_object = dn;
173:
174: for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent)
175: ;
176: entry_ptr->e_name = rdn_cpy (moddn->dn_rdn);
177:
178: add_arg.ada_entry = entry_ptr->e_attributes;
179:
180: if (rebind () != OK) {
181: entry_free (entry_ptr);
182: return;
183: }
184:
185: /* Strong authentication */
186: if (add_arg.ada_common.ca_security != (struct security_parms *) 0)
187: {
188: struct signature *sign_operation();
189: int encode_DAS_AddEntryArgumentData();
190:
191: add_arg.ada_common.ca_sig =
192: sign_operation((caddr_t)&add_arg, encode_DAS_AddEntryArgumentData);
193: }
194:
195: while (ds_addentry (&add_arg, &error) != DS_OK) {
196: if (dish_error (OPT, &error) == 0) {
197: entry_free (entry_ptr);
198: return;
199: }
200: add_arg.ada_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
201: }
202: ps_print (RPS, "Added ");
203: dn_print (RPS, dn, EDBOUT);
204: ps_print (RPS, "\n");
205:
206: delete_list_cache (dn);
207: entry_free (entry_ptr);
208:
209: make_old (fname,draft_flag);
210:
211: }
212:
213: make_old (file, commit)
214: char * file;
215: char commit;
216: {
217: char newname[LINESIZE];
218:
219: if (commit == 0) {
220: (void) sprintf (newname, "%s.old", file);
221: (void) rename (file, newname);
222: }
223: }
224:
225:
226: Attr_Sequence make_template_as (oc)
227: AV_Sequence oc;
228: {
229: AV_Sequence avs;
230: Attr_Sequence newas;
231: Attr_Sequence as = NULLATTR;
232: table_seq optr;
233: AttributeType at;
234: objectclass * ocp;
235:
236: for (avs = oc; avs != NULLAV; avs = avs->avseq_next) {
237: ocp = (objectclass *) avs->avseq_av.av_struct;
238: for (optr=ocp->oc_must; optr!=NULLTABLE_SEQ; optr=optr->ts_next) {
239: at = optr->ts_oa;
240: newas = as_comp_new (at,NULLAV,NULLACL_INFO);
241: as = as_merge (as,newas);
242: }
243: }
244:
245: for (avs = oc; avs != NULLAV; avs = avs->avseq_next) {
246: ocp = (objectclass *) avs->avseq_av.av_struct;
247: for (optr=ocp->oc_may; optr!=NULLTABLE_SEQ; optr=optr->ts_next) {
248: at = optr->ts_oa;
249: newas = as_comp_new (at,NULLAV,NULLACL_INFO);
250: as = as_merge (as,newas);
251: }
252: }
253:
254: return (as);
255: }
256:
257: add_template (name, objclass)
258: char *name;
259: char *objclass;
260: {
261: FILE *fptr;
262: PS ps;
263: char obuf[LINESIZE];
264: Attr_Sequence as;
265: Attr_Sequence ocas;
266: int um;
267:
268: if (objclass == NULLCP)
269: objclass = ORG_PERSON;
270:
271: if (!new_draft)
272: if ((fptr = fopen (name, "r")) != NULL) {
273: (void) fclose (fptr);
274: if (yesno ("Use existing draft file ? "))
275: return OK;
276: else
277: make_old (fname,FALSE);
278: return (OK); /* template already exists ! */
279: }
280: um = umask (0177);
281: if ((fptr = fopen (name, "w")) == NULL) {
282: ps_printf (OPT, "Can't open template entry %s\n", name);
283: return (-1);
284: }
285: (void) umask (um);
286: if ((ps = ps_alloc (std_open)) == NULLPS) {
287: return (-1);
288: }
289: if (std_setup (ps, fptr) == NOTOK) {
290: return (-1);
291: }
292:
293: (void) sprintf (obuf, "objectClass=%s", objclass);
294: if ((ocas = str2as (obuf)) == NULLATTR)
295: return (-1);
296:
297: as = make_template_as (ocas->attr_value);
298: as = as_merge (as,ocas);
299:
300: as_print (ps,as,EDBOUT);
301:
302: as_free (as);
303: ps_free (ps);
304: (void) fclose (fptr);
305:
306: return (OK);
307:
308: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.