2 * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 #ifdef HAVE_SYS_TYPES_H
49 #include <sys/types.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
54 #if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
55 #include <sys/ioctl.h>
57 #ifdef HAVE_SYS_IOCCOM_H
58 #include <sys/ioccom.h>
69 RCSID("$Id: aklog.c,v 1.24.2.1 2000/06/23 02:31:15 assar Exp $");
74 DEBUG(const char *, ...)
76 __attribute__ ((format (printf, 1, 2)))
81 DEBUG(const char *fmt, ...)
92 expand_1 (const char *cell, const char *filename)
98 f = fopen(filename, "r");
101 while(fgets(buf, sizeof(buf), f) != NULL) {
103 for(p=buf; *p && !isspace(*p) && *p != '#'; p++)
106 if(strstr(buf, cell)){
118 expand_cell_name(const char *cell)
122 ret = expand_1(cell, _PATH_CELLSERVDB);
125 ret = expand_1(cell, _PATH_ARLA_CELLSERVDB);
132 createuser (const char *cell)
136 char instance[INST_SZ];
137 char realm[REALM_SZ];
144 f = fopen (_PATH_THISCELL, "r");
146 f = fopen (_PATH_ARLA_THISCELL, "r");
148 err (1, "open(%s, %s)", _PATH_THISCELL, _PATH_ARLA_THISCELL);
149 if (fgets (cellbuf, sizeof(cellbuf), f) == NULL)
150 err (1, "read cellname from %s %s", _PATH_THISCELL, _PATH_ARLA_THISCELL);
152 len = strlen(cellbuf);
153 if (cellbuf[len-1] == '\n')
154 cellbuf[len-1] = '\0';
158 if(krb_get_default_principal(name, instance, realm))
159 errx (1, "Could not even figure out who you are");
161 snprintf (cmd, sizeof(cmd),
162 "pts createuser %s%s%s@%s -cell %s",
163 name, *instance ? "." : "", instance, strlwr(realm),
165 DEBUG("Executing %s", cmd);
170 main(int argc, char **argv)
174 int do_createuser = -1;
175 const char *cell = NULL;
179 set_progname (argv[0]);
184 for(i = 1; i < argc; i++){
185 if(!strncmp(argv[i], "-createuser", 11)){
186 do_createuser = do_aklog = 1;
188 }else if(!strncmp(argv[i], "-c", 2) && i + 1 < argc){
189 cell = expand_cell_name(argv[++i]);
192 }else if(!strncmp(argv[i], "-k", 2) && i + 1 < argc){
195 }else if(!strncmp(argv[i], "-p", 2) && i + 1 < argc){
196 if(k_afs_cell_of_file(argv[++i], cellbuf, sizeof(cellbuf)))
197 errx (1, "No cell found for file \"%s\".", argv[i]);
202 }else if(!strncmp(argv[i], "-unlog", 6)){
205 }else if(!strncmp(argv[i], "-hosts", 6)){
206 warnx ("Argument -hosts is not implemented.");
208 }else if(!strncmp(argv[i], "-zsubs", 6)){
209 warnx("Argument -zsubs is not implemented.");
211 }else if(!strncmp(argv[i], "-noprdb", 6)){
212 warnx("Argument -noprdb is not implemented.");
214 }else if(!strncmp(argv[i], "-d", 6)){
218 if(!strcmp(argv[i], ".") ||
219 !strcmp(argv[i], "..") ||
220 strchr(argv[i], '/')){
221 DEBUG("I guess that \"%s\" is a filename.", argv[i]);
222 if(k_afs_cell_of_file(argv[i], cellbuf, sizeof(cellbuf)))
223 errx (1, "No cell found for file \"%s\".", argv[i]);
226 DEBUG("The file \"%s\" lives in cell \"%s\".", argv[i], cell);
229 cell = expand_cell_name(argv[i]);
230 DEBUG("I guess that %s is cell %s.", argv[i], cell);
236 if(krb_afslog(cell, realm))
237 errx (1, "Failed getting tokens for cell %s in realm %s.",
238 cell?cell:"(local cell)", realm?realm:"(local realm)");
240 if(do_createuser == 1) {
243 errx (1, "Failed creating user in cell %s", cell?cell:"(local cell)");
246 if(do_aklog == -1 && do_createuser == -1 && krb_afslog(0, realm))
247 errx (1, "Failed getting tokens for cell %s in realm %s.",
248 cell?cell:"(local cell)", realm?realm:"(local realm)");