8260385a47b4b9a7d758ec373fcd701eff5dec62
[openafs.git] / src / libadmin / samples / cm_local_cell.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  *
9  * Portions Copyright (c) 2003 Apple Computer, Inc.
10  */
11
12 /*
13  * This file contains sample code for the client admin interface 
14  */
15
16 #include <afsconfig.h>
17 #include <afs/param.h>
18
19 #include <roken.h>
20
21 #ifdef AFS_NT40_ENV
22 #include <winsock2.h>
23 #include <pthread.h>
24 #endif
25
26 #include <rx/rx.h>
27 #include <rx/rxstat.h>
28
29 #include <afs/afs_Admin.h>
30 #include <afs/afs_clientAdmin.h>
31 #include <afs/afs_utilAdmin.h>
32
33 #ifdef AFS_DARWIN_ENV
34 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
35 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
36 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
37 #endif /* AFS_DARWIN_ENV */
38
39 void
40 Usage(void)
41 {
42     fprintf(stderr, "Usage: cm_local_cell <host> <port>\n");
43     exit(1);
44 }
45
46 void
47 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
48 {
49     char **argp = argv;
50
51     if (!*(++argp))
52         Usage();
53     *srvrName = *(argp++);
54     if (!*(argp))
55         Usage();
56     *srvrPort = strtol(*(argp++), NULL, 0);
57     if (*srvrPort <= 0 || *srvrPort >= 65536)
58         Usage();
59     if (*(argp))
60         Usage();
61 }
62
63 int
64 main(int argc, char *argv[])
65 {
66     int rc;
67     afs_status_t st = 0;
68     struct rx_connection *conn;
69     char *srvrName;
70     long srvrPort;
71     void *cellHandle;
72     afs_CMCellName_t cellName;
73
74     ParseArgs(argc, argv, &srvrName, &srvrPort);
75
76     rc = afsclient_Init(&st);
77     if (!rc) {
78         fprintf(stderr, "afsclient_Init, status %d\n", st);
79         exit(1);
80     }
81
82     rc = afsclient_NullCellOpen(&cellHandle, &st);
83     if (!rc) {
84         fprintf(stderr, "afsclient_NullCellsOpen, status %d\n", st);
85         exit(1);
86     }
87
88     rc = afsclient_CMStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st);
89     if (!rc) {
90         fprintf(stderr, "afsclient_CMStatOpenPort, status %d\n", st);
91         exit(1);
92     }
93
94     rc = util_CMLocalCell(conn, cellName, &st);
95     if (!rc) {
96         fprintf(stderr, "util_CMLocalCell, status %d\n", st);
97         exit(1);
98     }
99
100     rc = afsclient_CMStatClose(conn, &st);
101     if (!rc) {
102         fprintf(stderr, "afsclient_CMStatClose, status %d\n", st);
103         exit(1);
104     }
105
106     rc = afsclient_CellClose(cellHandle, &st);
107     if (!rc) {
108         fprintf(stderr, "afsclient_CellClose, status %d\n", st);
109         exit(1);
110     }
111
112     printf("\n");
113     printf("Client %s (port %ld) is in cell %s\n", srvrName, srvrPort,
114            cellName);
115     printf("\n");
116
117     exit(0);
118 }