1 /*******************************************************************************
5 ** $XConsortium: cm_admin.c /main/5 1996/07/09 14:48:00 drk $
7 ** RESTRICTED CONFIDENTIAL INFORMATION:
9 ** The information in this document is subject to special
10 ** restrictions in a confidential disclosure agreement between
11 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
13 ** Sun's specific written approval. This document and all copies
14 ** and derivative works thereof must be returned or destroyed at
17 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 *******************************************************************************/
22 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
23 * (c) Copyright 1993, 1994 International Business Machines Corp. *
24 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
25 * (c) Copyright 1993, 1994 Novell, Inc. *
29 static char sccsid[] = "@(#)cm_lookup.c 1.21 94/08/05 Copyr 1993 Sun Microsystems, Inc.";
32 #include <EUSCompat.h>
39 #include <sys/resource.h>
51 #if !defined(NL_CAT_LOCALE)
52 #define NL_CAT_LOCALE 0
55 typedef enum {archive, restore} Admin_mode;
57 static Admin_mode Mode = archive;
58 static char cm_target[MAXPATHLEN];
59 static char cm_start[MAXPATHLEN];
60 static char cm_end[MAXPATHLEN];
61 static char cm_file[MAXPATHLEN];
62 static int Delete = B_FALSE;
63 static FILE *input_stream = stdin;
64 static FILE *output_stream = stdout;
67 static nl_catd DT_catd;
70 grab(char**argv, /* command line arguments */
71 char *buf, /* buffer for keyed data */
74 if (!argv || !*argv) return(argv);
75 cm_strcpy (buf,*argv++);
76 while(argv && *argv) {
77 if (*(*argv) == stop_key) break;
79 cm_strcat(buf,*argv++);
87 fprintf(stderr,catgets(DT_catd, 1, 696, "Usage:\n\tdtcm_admin [ -d ] [ -a action ] [ -c calendar ][ -s <mm/dd/yy> ] [ -e <mm/dd/yy> ] [-f filename]\n"));
91 cm_args(int argc, char **argv)
94 while (++argv && *argv) {
98 if (strcmp(*argv, "archive") == 0)
100 else if (strcmp(*argv, "restore") == 0)
103 fprintf(stderr,catgets(DT_catd, 1, 697, "You have specified an unsupported administration operation \"%s\".\n"), *argv);
109 argv = grab(++argv,cm_target,'-');
112 argv = grab(++argv,cm_start,'-');
115 argv = grab(++argv,cm_end,'-');
118 argv = grab(++argv,cm_file,'-');
132 int main(int argc, char **argv)
135 char *target = NULL, *date = NULL, *view = NULL,
138 CSA_session_handle c_handle;
139 CSA_entry_handle *list;
140 CSA_calendar_user csa_user;
141 CSA_return_code stat;
147 setlocale(LC_ALL, "");
148 DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
149 cm_tty_load_props(&p);
150 cm_args(argc,argv); /* parse command line */
152 target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials();
155 if (cmfns_use_fns(p)) {
156 cmfns_lookup_calendar(target, buf, sizeof(buf));
160 uname = cm_target2name(target);
161 loc = cm_target2location(target);
163 /* check to see if the file name parameter makes sense */
166 if (Mode == archive) {
167 if ((output_stream = fopen(cm_file, "w")) == NULL) {
168 fprintf(stderr, catgets(DT_catd, 1, 698, "\nCould not open output file \"%s\"\n"), cm_file);
174 if (Mode == restore) {
175 if ((input_stream = fopen(cm_file, "r")) == NULL) {
176 fprintf(stderr, catgets(DT_catd, 1, 699, "\nCould not open input file \"%s\"\n"), cm_file);
181 csa_user.user_name = target;
182 csa_user.user_type = 0;
183 csa_user.calendar_user_extensions = NULL;
184 csa_user.calendar_address = target;
185 stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
187 if (stat != CSA_SUCCESS) {
188 char *format = XtNewString(catgets(DT_catd, 1, 208,
189 "\nCould not open calendar \"%s\"\n"));
190 fprintf(stderr, format,
191 target ? target : catgets(DT_catd, 1, 209, "UNKNOWN"));
198 csa_logoff(c_handle, NULL);