1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * gsscred utility 31*7c478bd9Sstevel@tonic-gate * Manages mapping between a security principal name and unix uid 32*7c478bd9Sstevel@tonic-gate */ 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include <stdio.h> 35*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 36*7c478bd9Sstevel@tonic-gate #include <pwd.h> 37*7c478bd9Sstevel@tonic-gate #include <unistd.h> 38*7c478bd9Sstevel@tonic-gate #include <string.h> 39*7c478bd9Sstevel@tonic-gate #include <gssapi/gssapi_ext.h> 40*7c478bd9Sstevel@tonic-gate #include "gsscred.h" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #define MAX_STR_LEN 1024 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate /* 46*7c478bd9Sstevel@tonic-gate * Internal Functions 47*7c478bd9Sstevel@tonic-gate */ 48*7c478bd9Sstevel@tonic-gate static void usage(void); 49*7c478bd9Sstevel@tonic-gate static void addUser(const char *name, const char *oid, const char *userUid, 50*7c478bd9Sstevel@tonic-gate const char *userComment, const char *userMech); 51*7c478bd9Sstevel@tonic-gate static int file_listUsers(const gss_OID mechOid, const char *userUid, 52*7c478bd9Sstevel@tonic-gate char **errDetails); 53*7c478bd9Sstevel@tonic-gate static int listUsers(const char *name, const char *nameTypeOid, 54*7c478bd9Sstevel@tonic-gate const char *uid, const char *mechOid); 55*7c478bd9Sstevel@tonic-gate static int file_removeUsers(const gss_OID mechOid, const char *userUid, 56*7c478bd9Sstevel@tonic-gate char **errDetails); 57*7c478bd9Sstevel@tonic-gate static int removeUsers(const char *name, const char *nameTypeOid, 58*7c478bd9Sstevel@tonic-gate const char *uid, const char *mechOid); 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate /* 61*7c478bd9Sstevel@tonic-gate * Global variables 62*7c478bd9Sstevel@tonic-gate */ 63*7c478bd9Sstevel@tonic-gate static int tableSource; 64*7c478bd9Sstevel@tonic-gate static char *PROG_NAME = NULL; 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate int 67*7c478bd9Sstevel@tonic-gate main(int argc, char *args[]) 68*7c478bd9Sstevel@tonic-gate { 69*7c478bd9Sstevel@tonic-gate char *userName = NULL, *nameTypeOID = NULL, 70*7c478bd9Sstevel@tonic-gate *uid = NULL, *comment = NULL, *mech = NULL, 71*7c478bd9Sstevel@tonic-gate operation = '0'; 72*7c478bd9Sstevel@tonic-gate int c, errflag = 0; 73*7c478bd9Sstevel@tonic-gate extern char *optarg; 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate PROG_NAME = *args; 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate /* set locale and domain for internationalization */ 78*7c478bd9Sstevel@tonic-gate setlocale(LC_ALL, ""); 79*7c478bd9Sstevel@tonic-gate textdomain(TEXT_DOMAIN); 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate if (argc < 2) 82*7c478bd9Sstevel@tonic-gate usage(); 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate /* Process the input arguments */ 85*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, args, "arln:o:u:m:c:")) != EOF) { 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate switch (c) { 88*7c478bd9Sstevel@tonic-gate case 'n': 89*7c478bd9Sstevel@tonic-gate userName = optarg; 90*7c478bd9Sstevel@tonic-gate break; 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate case 'o': 93*7c478bd9Sstevel@tonic-gate nameTypeOID = optarg; 94*7c478bd9Sstevel@tonic-gate break; 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate case 'u': 97*7c478bd9Sstevel@tonic-gate uid = optarg; 98*7c478bd9Sstevel@tonic-gate break; 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate case 'm': 101*7c478bd9Sstevel@tonic-gate mech = optarg; 102*7c478bd9Sstevel@tonic-gate break; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate case 'c': 105*7c478bd9Sstevel@tonic-gate comment = optarg; 106*7c478bd9Sstevel@tonic-gate break; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate case 'a': 109*7c478bd9Sstevel@tonic-gate case 'r': 110*7c478bd9Sstevel@tonic-gate case 'l': 111*7c478bd9Sstevel@tonic-gate operation = c; 112*7c478bd9Sstevel@tonic-gate errflag++; 113*7c478bd9Sstevel@tonic-gate if (errflag > 1) 114*7c478bd9Sstevel@tonic-gate usage(); 115*7c478bd9Sstevel@tonic-gate break; 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate default: 118*7c478bd9Sstevel@tonic-gate usage(); 119*7c478bd9Sstevel@tonic-gate } 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* determine which back-end to use as the gsscred store */ 123*7c478bd9Sstevel@tonic-gate tableSource = gsscred_read_config_file(); 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate /* perform the requested operation */ 126*7c478bd9Sstevel@tonic-gate switch (operation) { 127*7c478bd9Sstevel@tonic-gate case 'a': 128*7c478bd9Sstevel@tonic-gate addUser(userName, nameTypeOID, uid, comment, mech); 129*7c478bd9Sstevel@tonic-gate break; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate case 'r': 132*7c478bd9Sstevel@tonic-gate removeUsers(userName, nameTypeOID, uid, mech); 133*7c478bd9Sstevel@tonic-gate break; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate case 'l': 136*7c478bd9Sstevel@tonic-gate listUsers(userName, nameTypeOID, uid, mech); 137*7c478bd9Sstevel@tonic-gate break; 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate default: 140*7c478bd9Sstevel@tonic-gate usage(); 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate fprintf(stdout, "\n"); 143*7c478bd9Sstevel@tonic-gate return (0); 144*7c478bd9Sstevel@tonic-gate } /* main */ 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate /* 147*7c478bd9Sstevel@tonic-gate * Handles the addition of users to the gsscred table. 148*7c478bd9Sstevel@tonic-gate */ 149*7c478bd9Sstevel@tonic-gate static void 150*7c478bd9Sstevel@tonic-gate addUser(const char *name, const char *nameOidStr, 151*7c478bd9Sstevel@tonic-gate const char *userUid, const char *userComment, 152*7c478bd9Sstevel@tonic-gate const char *mechOidStr) 153*7c478bd9Sstevel@tonic-gate { 154*7c478bd9Sstevel@tonic-gate gss_OID mechOid; 155*7c478bd9Sstevel@tonic-gate gss_buffer_desc fullName = GSS_C_EMPTY_BUFFER, 156*7c478bd9Sstevel@tonic-gate hexBufDesc = GSS_C_EMPTY_BUFFER, 157*7c478bd9Sstevel@tonic-gate hexMechOid = GSS_C_EMPTY_BUFFER; 158*7c478bd9Sstevel@tonic-gate char comment[MAX_STR_LEN+1], hexBuf[MAX_STR_LEN+MAX_STR_LEN+1], 159*7c478bd9Sstevel@tonic-gate hexMechOidBuf[MAX_STR_LEN+1], *commentPtr = NULL, 160*7c478bd9Sstevel@tonic-gate *errDetail = NULL, uidStr[256], *uidPtr; 161*7c478bd9Sstevel@tonic-gate struct passwd *aUser; 162*7c478bd9Sstevel@tonic-gate OM_uint32 minor; 163*7c478bd9Sstevel@tonic-gate int count = 0, retCode; 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate hexMechOid.length = MAX_STR_LEN; 166*7c478bd9Sstevel@tonic-gate hexMechOid.value = (void*)hexMechOidBuf; 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate /* addition of users can only be performed by super users */ 169*7c478bd9Sstevel@tonic-gate if (getuid()) { 170*7c478bd9Sstevel@tonic-gate fprintf(stderr, 171*7c478bd9Sstevel@tonic-gate gettext("\nUser addition requires" 172*7c478bd9Sstevel@tonic-gate " root privileges.")); 173*7c478bd9Sstevel@tonic-gate return; 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate /* the mechanism OID is required */ 177*7c478bd9Sstevel@tonic-gate if (mechOidStr == NULL) { 178*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("\nUnspecified mechanism.")); 179*7c478bd9Sstevel@tonic-gate usage(); 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate /* Convert from string mechanism Oid to ASN.1 oid and then hex */ 183*7c478bd9Sstevel@tonic-gate if (__gss_mech_to_oid(mechOidStr, &mechOid) != GSS_S_COMPLETE) { 184*7c478bd9Sstevel@tonic-gate fprintf(stderr, 185*7c478bd9Sstevel@tonic-gate gettext("\nInvalid mechanism specified [%s]."), 186*7c478bd9Sstevel@tonic-gate mechOidStr); 187*7c478bd9Sstevel@tonic-gate return; 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate hexBufDesc.length = mechOid->length; 191*7c478bd9Sstevel@tonic-gate hexBufDesc.value = mechOid->elements; 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&hexBufDesc, &hexMechOid)) { 194*7c478bd9Sstevel@tonic-gate fprintf(stderr, 195*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 196*7c478bd9Sstevel@tonic-gate "Conversion to hex failed.")); 197*7c478bd9Sstevel@tonic-gate return; 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate /* 201*7c478bd9Sstevel@tonic-gate * if the name is specified, then do single addition. 202*7c478bd9Sstevel@tonic-gate * Might have to look up the uid. 203*7c478bd9Sstevel@tonic-gate */ 204*7c478bd9Sstevel@tonic-gate if (name != NULL) { 205*7c478bd9Sstevel@tonic-gate hexBufDesc.length = sizeof (hexBuf); 206*7c478bd9Sstevel@tonic-gate hexBufDesc.value = hexBuf; 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* build the name as needed */ 209*7c478bd9Sstevel@tonic-gate if (!gsscred_MakeName(mechOid, name, nameOidStr, &fullName)) { 210*7c478bd9Sstevel@tonic-gate fprintf(stderr, 211*7c478bd9Sstevel@tonic-gate gettext("\nError adding user [%s]."), name); 212*7c478bd9Sstevel@tonic-gate return; 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate /* convert it to hex */ 216*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&fullName, &hexBufDesc)) { 217*7c478bd9Sstevel@tonic-gate gss_release_buffer(&minor, &fullName); 218*7c478bd9Sstevel@tonic-gate fprintf(stderr, 219*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 220*7c478bd9Sstevel@tonic-gate "Conversion to hex failed.")); 221*7c478bd9Sstevel@tonic-gate return; 222*7c478bd9Sstevel@tonic-gate } 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate /* might require the lookup of the uid if one not specified */ 225*7c478bd9Sstevel@tonic-gate if (userUid == NULL) { 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate if ((aUser = getpwnam(name)) == NULL) { 228*7c478bd9Sstevel@tonic-gate fprintf(stderr, 229*7c478bd9Sstevel@tonic-gate gettext("\nUnable to obtain password" 230*7c478bd9Sstevel@tonic-gate " information for [%s]."), 231*7c478bd9Sstevel@tonic-gate name); 232*7c478bd9Sstevel@tonic-gate gss_release_buffer(&minor, &fullName); 233*7c478bd9Sstevel@tonic-gate return; 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate sprintf(uidStr, "%ld", aUser->pw_uid); 236*7c478bd9Sstevel@tonic-gate uidPtr = uidStr; 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate else 239*7c478bd9Sstevel@tonic-gate uidPtr = (char *)userUid; 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate if (userComment == NULL) { 242*7c478bd9Sstevel@tonic-gate sprintf(comment, "%s, %s", name, mechOidStr); 243*7c478bd9Sstevel@tonic-gate commentPtr = comment; 244*7c478bd9Sstevel@tonic-gate } else 245*7c478bd9Sstevel@tonic-gate commentPtr = (char *)userComment; 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 248*7c478bd9Sstevel@tonic-gate retCode = file_addGssCredEntry(&hexBufDesc, 249*7c478bd9Sstevel@tonic-gate uidPtr, commentPtr, &errDetail); 250*7c478bd9Sstevel@tonic-gate else 251*7c478bd9Sstevel@tonic-gate /* other backends (ldap, dss) coming soon */ 252*7c478bd9Sstevel@tonic-gate retCode = 0; 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate if (!retCode) { 255*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("\nError adding user [%s]."), 256*7c478bd9Sstevel@tonic-gate commentPtr); 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate if (errDetail) { 259*7c478bd9Sstevel@tonic-gate fprintf(stderr, "\n%s\n", errDetail); 260*7c478bd9Sstevel@tonic-gate free(errDetail); 261*7c478bd9Sstevel@tonic-gate errDetail = NULL; 262*7c478bd9Sstevel@tonic-gate } 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate gss_release_buffer(&minor, &fullName); 266*7c478bd9Sstevel@tonic-gate return; 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate /* 270*7c478bd9Sstevel@tonic-gate * since no name specified, then we will load everyone from 271*7c478bd9Sstevel@tonic-gate * password table. This means that -u and -o options are invalid. 272*7c478bd9Sstevel@tonic-gate * We just ignore it, but we could flag it as error. 273*7c478bd9Sstevel@tonic-gate */ 274*7c478bd9Sstevel@tonic-gate setpwent(); 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate while ((aUser = getpwent()) != NULL) { 277*7c478bd9Sstevel@tonic-gate hexBufDesc.length = sizeof (hexBuf); 278*7c478bd9Sstevel@tonic-gate hexBufDesc.value = hexBuf; 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate if (!gsscred_MakeName(mechOid, aUser->pw_name, 281*7c478bd9Sstevel@tonic-gate nameOidStr, &fullName)) { 282*7c478bd9Sstevel@tonic-gate fprintf(stderr, 283*7c478bd9Sstevel@tonic-gate gettext("\nError adding user [%s]."), 284*7c478bd9Sstevel@tonic-gate aUser->pw_name); 285*7c478bd9Sstevel@tonic-gate continue; 286*7c478bd9Sstevel@tonic-gate } 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&fullName, &hexBufDesc)) { 289*7c478bd9Sstevel@tonic-gate gss_release_buffer(&minor, &fullName); 290*7c478bd9Sstevel@tonic-gate fprintf(stderr, 291*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 292*7c478bd9Sstevel@tonic-gate "Conversion to hex failed.")); 293*7c478bd9Sstevel@tonic-gate continue; 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate sprintf(uidStr, "%ld", aUser->pw_uid); 297*7c478bd9Sstevel@tonic-gate sprintf(comment, "%s, %s", aUser->pw_name, mechOidStr); 298*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 299*7c478bd9Sstevel@tonic-gate retCode = file_addGssCredEntry(&hexBufDesc, 300*7c478bd9Sstevel@tonic-gate uidStr, comment, &errDetail); 301*7c478bd9Sstevel@tonic-gate else 302*7c478bd9Sstevel@tonic-gate retCode = 0; 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate if (!retCode) { 305*7c478bd9Sstevel@tonic-gate fprintf(stderr, 306*7c478bd9Sstevel@tonic-gate gettext("\nError adding user [%s]."), 307*7c478bd9Sstevel@tonic-gate comment); 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate if (errDetail) { 310*7c478bd9Sstevel@tonic-gate fprintf(stderr, "\n%s\n", errDetail); 311*7c478bd9Sstevel@tonic-gate free(errDetail); 312*7c478bd9Sstevel@tonic-gate errDetail = NULL; 313*7c478bd9Sstevel@tonic-gate } 314*7c478bd9Sstevel@tonic-gate } else { 315*7c478bd9Sstevel@tonic-gate count++; 316*7c478bd9Sstevel@tonic-gate if ((count % 50) == 0) 317*7c478bd9Sstevel@tonic-gate fprintf(stdout, 318*7c478bd9Sstevel@tonic-gate gettext("\n[%d] users added..."), 319*7c478bd9Sstevel@tonic-gate count); 320*7c478bd9Sstevel@tonic-gate } 321*7c478bd9Sstevel@tonic-gate gss_release_buffer(&minor, &fullName); 322*7c478bd9Sstevel@tonic-gate } 323*7c478bd9Sstevel@tonic-gate endpwent(); 324*7c478bd9Sstevel@tonic-gate } /* addUser */ 325*7c478bd9Sstevel@tonic-gate 326*7c478bd9Sstevel@tonic-gate 327*7c478bd9Sstevel@tonic-gate /* 328*7c478bd9Sstevel@tonic-gate * Handles the searching of the gsscred table. 329*7c478bd9Sstevel@tonic-gate */ 330*7c478bd9Sstevel@tonic-gate static int listUsers(const char *name, const char *nameOidStr, 331*7c478bd9Sstevel@tonic-gate const char *uidStr, const char *mechOidStr) 332*7c478bd9Sstevel@tonic-gate { 333*7c478bd9Sstevel@tonic-gate GssCredEntry *entryPtr, *entryTmpPtr; 334*7c478bd9Sstevel@tonic-gate char hexMech[256], 335*7c478bd9Sstevel@tonic-gate hexName[(MAX_STR_LEN *2) + 1]; 336*7c478bd9Sstevel@tonic-gate gss_OID anOid = NULL, userMechOid = NULL; 337*7c478bd9Sstevel@tonic-gate gss_OID_set mechSet = NULL; 338*7c478bd9Sstevel@tonic-gate gss_buffer_desc inBufDesc = GSS_C_EMPTY_BUFFER, 339*7c478bd9Sstevel@tonic-gate outBufDesc = GSS_C_EMPTY_BUFFER, 340*7c478bd9Sstevel@tonic-gate searchName = GSS_C_EMPTY_BUFFER; 341*7c478bd9Sstevel@tonic-gate int status = 1, numOfMechs, i; 342*7c478bd9Sstevel@tonic-gate OM_uint32 minor; 343*7c478bd9Sstevel@tonic-gate char *errDetails = NULL; 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate /* Do we need to convert the mechanism oid? */ 346*7c478bd9Sstevel@tonic-gate if (mechOidStr != NULL) { 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate if (__gss_mech_to_oid(mechOidStr, &userMechOid) != 349*7c478bd9Sstevel@tonic-gate GSS_S_COMPLETE) { 350*7c478bd9Sstevel@tonic-gate fprintf(stderr, 351*7c478bd9Sstevel@tonic-gate gettext("\nInvalid mechanism specified [%s]."), 352*7c478bd9Sstevel@tonic-gate mechOidStr); 353*7c478bd9Sstevel@tonic-gate return (0); 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate inBufDesc.length = userMechOid->length; 356*7c478bd9Sstevel@tonic-gate inBufDesc.value = userMechOid->elements; 357*7c478bd9Sstevel@tonic-gate outBufDesc.length = sizeof (hexMech); 358*7c478bd9Sstevel@tonic-gate outBufDesc.value = hexMech; 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&inBufDesc, &outBufDesc)) { 361*7c478bd9Sstevel@tonic-gate fprintf(stderr, 362*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 363*7c478bd9Sstevel@tonic-gate "Conversion to hex failed.")); 364*7c478bd9Sstevel@tonic-gate status = 0; 365*7c478bd9Sstevel@tonic-gate goto cleanup; 366*7c478bd9Sstevel@tonic-gate } 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate } /* mechOidStr != NULL */ 369*7c478bd9Sstevel@tonic-gate 370*7c478bd9Sstevel@tonic-gate /* are we retrieving everyone ? or searching by mech ? */ 371*7c478bd9Sstevel@tonic-gate if ((name == NULL && uidStr == NULL && mechOidStr == NULL) || 372*7c478bd9Sstevel@tonic-gate (name == NULL && uidStr == NULL)) { 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) { 375*7c478bd9Sstevel@tonic-gate file_listUsers(userMechOid, NULL, &errDetails); 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate if (errDetails) { 378*7c478bd9Sstevel@tonic-gate fprintf(stderr, 379*7c478bd9Sstevel@tonic-gate gettext("\nError searching gsscred" 380*7c478bd9Sstevel@tonic-gate " table [%s]."), 381*7c478bd9Sstevel@tonic-gate errDetails); 382*7c478bd9Sstevel@tonic-gate free(errDetails); 383*7c478bd9Sstevel@tonic-gate errDetails = NULL; 384*7c478bd9Sstevel@tonic-gate return (0); 385*7c478bd9Sstevel@tonic-gate } 386*7c478bd9Sstevel@tonic-gate return (1); 387*7c478bd9Sstevel@tonic-gate } 388*7c478bd9Sstevel@tonic-gate 389*7c478bd9Sstevel@tonic-gate } 390*7c478bd9Sstevel@tonic-gate 391*7c478bd9Sstevel@tonic-gate /* Are we searching by uid or uid and mech? */ 392*7c478bd9Sstevel@tonic-gate if (name == NULL && uidStr != NULL) { 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 395*7c478bd9Sstevel@tonic-gate file_listUsers(userMechOid, uidStr, &errDetails); 396*7c478bd9Sstevel@tonic-gate else { 397*7c478bd9Sstevel@tonic-gate entryPtr = NULL; 398*7c478bd9Sstevel@tonic-gate while (entryPtr != NULL) { 399*7c478bd9Sstevel@tonic-gate fprintf(stdout, "\n%s\t%d\t%s", 400*7c478bd9Sstevel@tonic-gate entryPtr->principal_name, 401*7c478bd9Sstevel@tonic-gate entryPtr->unix_uid, entryPtr->comment); 402*7c478bd9Sstevel@tonic-gate free(entryPtr->principal_name); 403*7c478bd9Sstevel@tonic-gate free(entryPtr->comment); 404*7c478bd9Sstevel@tonic-gate entryTmpPtr = entryPtr->next; 405*7c478bd9Sstevel@tonic-gate free(entryPtr); 406*7c478bd9Sstevel@tonic-gate entryPtr = entryTmpPtr; 407*7c478bd9Sstevel@tonic-gate } 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate /* check for any errors */ 411*7c478bd9Sstevel@tonic-gate if (errDetails) { 412*7c478bd9Sstevel@tonic-gate fprintf(stderr, 413*7c478bd9Sstevel@tonic-gate gettext("\nError searching gsscred table " 414*7c478bd9Sstevel@tonic-gate "[%s]."), 415*7c478bd9Sstevel@tonic-gate errDetails); 416*7c478bd9Sstevel@tonic-gate free(errDetails); 417*7c478bd9Sstevel@tonic-gate errDetails = NULL; 418*7c478bd9Sstevel@tonic-gate status = 0; 419*7c478bd9Sstevel@tonic-gate } 420*7c478bd9Sstevel@tonic-gate 421*7c478bd9Sstevel@tonic-gate goto cleanup; 422*7c478bd9Sstevel@tonic-gate } 423*7c478bd9Sstevel@tonic-gate 424*7c478bd9Sstevel@tonic-gate /* 425*7c478bd9Sstevel@tonic-gate * We are searching by name; 426*7c478bd9Sstevel@tonic-gate * how many mechs must we check? 427*7c478bd9Sstevel@tonic-gate */ 428*7c478bd9Sstevel@tonic-gate if (mechOidStr == NULL) { 429*7c478bd9Sstevel@tonic-gate 430*7c478bd9Sstevel@tonic-gate if (gss_indicate_mechs(&minor, &mechSet) != GSS_S_COMPLETE) { 431*7c478bd9Sstevel@tonic-gate fprintf(stderr, 432*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 433*7c478bd9Sstevel@tonic-gate "GSS-API call failed.")); 434*7c478bd9Sstevel@tonic-gate return (0); 435*7c478bd9Sstevel@tonic-gate } 436*7c478bd9Sstevel@tonic-gate numOfMechs = mechSet->count; 437*7c478bd9Sstevel@tonic-gate } 438*7c478bd9Sstevel@tonic-gate else 439*7c478bd9Sstevel@tonic-gate numOfMechs = 1; 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate /* now look through all the mechs searching */ 442*7c478bd9Sstevel@tonic-gate for (i = 0; i < numOfMechs; i++) { 443*7c478bd9Sstevel@tonic-gate 444*7c478bd9Sstevel@tonic-gate if (mechOidStr == NULL) { 445*7c478bd9Sstevel@tonic-gate anOid = &mechSet->elements[i]; 446*7c478bd9Sstevel@tonic-gate inBufDesc.length = anOid->length; 447*7c478bd9Sstevel@tonic-gate inBufDesc.value = anOid->elements; 448*7c478bd9Sstevel@tonic-gate outBufDesc.length = sizeof (hexMech); 449*7c478bd9Sstevel@tonic-gate outBufDesc.value = hexMech; 450*7c478bd9Sstevel@tonic-gate 451*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&inBufDesc, &outBufDesc)) 452*7c478bd9Sstevel@tonic-gate continue; 453*7c478bd9Sstevel@tonic-gate } else 454*7c478bd9Sstevel@tonic-gate anOid = userMechOid; 455*7c478bd9Sstevel@tonic-gate 456*7c478bd9Sstevel@tonic-gate /* create a gss name */ 457*7c478bd9Sstevel@tonic-gate if (!gsscred_MakeName(anOid, name, nameOidStr, &outBufDesc)) 458*7c478bd9Sstevel@tonic-gate continue; 459*7c478bd9Sstevel@tonic-gate 460*7c478bd9Sstevel@tonic-gate /* now convert it to hex, and find it */ 461*7c478bd9Sstevel@tonic-gate searchName.value = hexName; 462*7c478bd9Sstevel@tonic-gate searchName.length = sizeof (hexName); 463*7c478bd9Sstevel@tonic-gate status = gsscred_AsHex(&outBufDesc, &searchName); 464*7c478bd9Sstevel@tonic-gate free(outBufDesc.value); 465*7c478bd9Sstevel@tonic-gate 466*7c478bd9Sstevel@tonic-gate if (!status) 467*7c478bd9Sstevel@tonic-gate continue; 468*7c478bd9Sstevel@tonic-gate 469*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 470*7c478bd9Sstevel@tonic-gate file_getGssCredEntry(&searchName, uidStr, &errDetails); 471*7c478bd9Sstevel@tonic-gate else { 472*7c478bd9Sstevel@tonic-gate entryPtr = NULL; /* other backends coming soon */ 473*7c478bd9Sstevel@tonic-gate while (entryPtr != NULL) { 474*7c478bd9Sstevel@tonic-gate fprintf(stdout, "\n%s\t%d\t%s", 475*7c478bd9Sstevel@tonic-gate entryPtr->principal_name, 476*7c478bd9Sstevel@tonic-gate entryPtr->unix_uid, entryPtr->comment); 477*7c478bd9Sstevel@tonic-gate free(entryPtr->principal_name); 478*7c478bd9Sstevel@tonic-gate free(entryPtr->comment); 479*7c478bd9Sstevel@tonic-gate entryTmpPtr = entryPtr->next; 480*7c478bd9Sstevel@tonic-gate free(entryPtr); 481*7c478bd9Sstevel@tonic-gate entryPtr = entryTmpPtr; 482*7c478bd9Sstevel@tonic-gate } 483*7c478bd9Sstevel@tonic-gate } 484*7c478bd9Sstevel@tonic-gate 485*7c478bd9Sstevel@tonic-gate /* any errors to display */ 486*7c478bd9Sstevel@tonic-gate if (errDetails) { 487*7c478bd9Sstevel@tonic-gate fprintf(stderr, 488*7c478bd9Sstevel@tonic-gate gettext("\nError searching gsscred table " 489*7c478bd9Sstevel@tonic-gate "[%s]."), 490*7c478bd9Sstevel@tonic-gate errDetails); 491*7c478bd9Sstevel@tonic-gate free(errDetails); 492*7c478bd9Sstevel@tonic-gate errDetails = NULL; 493*7c478bd9Sstevel@tonic-gate status = 0; 494*7c478bd9Sstevel@tonic-gate } 495*7c478bd9Sstevel@tonic-gate } /* for */ 496*7c478bd9Sstevel@tonic-gate 497*7c478bd9Sstevel@tonic-gate cleanup: 498*7c478bd9Sstevel@tonic-gate if (mechSet != NULL) 499*7c478bd9Sstevel@tonic-gate gss_release_oid_set(&minor, &mechSet); 500*7c478bd9Sstevel@tonic-gate 501*7c478bd9Sstevel@tonic-gate return (status); 502*7c478bd9Sstevel@tonic-gate } /* listUsers */ 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate /* 505*7c478bd9Sstevel@tonic-gate * Performs additional handling while searching for users 506*7c478bd9Sstevel@tonic-gate * stored in the flat file table. 507*7c478bd9Sstevel@tonic-gate */ 508*7c478bd9Sstevel@tonic-gate int 509*7c478bd9Sstevel@tonic-gate file_listUsers(const gss_OID mechOid, const char *unixUid, 510*7c478bd9Sstevel@tonic-gate char **errDetails) 511*7c478bd9Sstevel@tonic-gate { 512*7c478bd9Sstevel@tonic-gate gss_buffer_desc mechBufDesc = GSS_C_EMPTY_BUFFER, 513*7c478bd9Sstevel@tonic-gate mechHexBufDesc = GSS_C_EMPTY_BUFFER; 514*7c478bd9Sstevel@tonic-gate char mechBuf[128], mechHexBuf[256]; 515*7c478bd9Sstevel@tonic-gate 516*7c478bd9Sstevel@tonic-gate if (mechOid != NULL) { 517*7c478bd9Sstevel@tonic-gate /* must make the name header whic contains mech oid */ 518*7c478bd9Sstevel@tonic-gate mechBufDesc.value = (void *) mechBuf; 519*7c478bd9Sstevel@tonic-gate mechBufDesc.length = sizeof (mechBuf); 520*7c478bd9Sstevel@tonic-gate mechHexBufDesc.value = (void*) mechHexBuf; 521*7c478bd9Sstevel@tonic-gate mechHexBufDesc.length = sizeof (mechHexBuf); 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate if ((!gsscred_MakeNameHeader(mechOid, &mechBufDesc)) || 524*7c478bd9Sstevel@tonic-gate (!gsscred_AsHex(&mechBufDesc, &mechHexBufDesc))) { 525*7c478bd9Sstevel@tonic-gate (*errDetails) = strdup( 526*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 527*7c478bd9Sstevel@tonic-gate " Conversion to hex failed.")); 528*7c478bd9Sstevel@tonic-gate return (0); 529*7c478bd9Sstevel@tonic-gate } 530*7c478bd9Sstevel@tonic-gate 531*7c478bd9Sstevel@tonic-gate return (file_getGssCredEntry(&mechHexBufDesc, 532*7c478bd9Sstevel@tonic-gate unixUid, errDetails)); 533*7c478bd9Sstevel@tonic-gate } 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate return (file_getGssCredEntry(NULL, unixUid, errDetails)); 536*7c478bd9Sstevel@tonic-gate } /* file_listUsers */ 537*7c478bd9Sstevel@tonic-gate 538*7c478bd9Sstevel@tonic-gate 539*7c478bd9Sstevel@tonic-gate /* 540*7c478bd9Sstevel@tonic-gate * Handles the deletion of users. 541*7c478bd9Sstevel@tonic-gate */ 542*7c478bd9Sstevel@tonic-gate static int removeUsers(const char *name, const char *nameOidStr, 543*7c478bd9Sstevel@tonic-gate const char *uidStr, const char *mechOidStr) 544*7c478bd9Sstevel@tonic-gate { 545*7c478bd9Sstevel@tonic-gate char hexMech[256], 546*7c478bd9Sstevel@tonic-gate hexName[(MAX_STR_LEN *2) + 1], 547*7c478bd9Sstevel@tonic-gate *errDetails = NULL; 548*7c478bd9Sstevel@tonic-gate gss_OID anOid = NULL, userMechOid = NULL; 549*7c478bd9Sstevel@tonic-gate gss_OID_set mechSet = NULL; 550*7c478bd9Sstevel@tonic-gate gss_buffer_desc inBufDesc = GSS_C_EMPTY_BUFFER, 551*7c478bd9Sstevel@tonic-gate outBufDesc = GSS_C_EMPTY_BUFFER, 552*7c478bd9Sstevel@tonic-gate searchName = GSS_C_EMPTY_BUFFER; 553*7c478bd9Sstevel@tonic-gate int status = 0, numOfMechs, i; 554*7c478bd9Sstevel@tonic-gate OM_uint32 minor; 555*7c478bd9Sstevel@tonic-gate 556*7c478bd9Sstevel@tonic-gate 557*7c478bd9Sstevel@tonic-gate /* user deletion can only be performed by super user */ 558*7c478bd9Sstevel@tonic-gate if (getuid()) { 559*7c478bd9Sstevel@tonic-gate 560*7c478bd9Sstevel@tonic-gate fprintf(stderr, 561*7c478bd9Sstevel@tonic-gate gettext("\nUser deletion requires" 562*7c478bd9Sstevel@tonic-gate " root privileges.")); 563*7c478bd9Sstevel@tonic-gate return (0); 564*7c478bd9Sstevel@tonic-gate } 565*7c478bd9Sstevel@tonic-gate 566*7c478bd9Sstevel@tonic-gate /* do we need to convert the mechanism oid? */ 567*7c478bd9Sstevel@tonic-gate if (mechOidStr != NULL) { 568*7c478bd9Sstevel@tonic-gate if (__gss_mech_to_oid(mechOidStr, &userMechOid) != 569*7c478bd9Sstevel@tonic-gate GSS_S_COMPLETE) { 570*7c478bd9Sstevel@tonic-gate fprintf(stderr, 571*7c478bd9Sstevel@tonic-gate gettext("\nInvalid mechanism specified [%s]."), 572*7c478bd9Sstevel@tonic-gate mechOidStr); 573*7c478bd9Sstevel@tonic-gate return (0); 574*7c478bd9Sstevel@tonic-gate } 575*7c478bd9Sstevel@tonic-gate 576*7c478bd9Sstevel@tonic-gate inBufDesc.length = userMechOid->length; 577*7c478bd9Sstevel@tonic-gate inBufDesc.value = userMechOid->elements; 578*7c478bd9Sstevel@tonic-gate outBufDesc.length = sizeof (hexMech); 579*7c478bd9Sstevel@tonic-gate outBufDesc.value = hexMech; 580*7c478bd9Sstevel@tonic-gate 581*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&inBufDesc, &outBufDesc)) { 582*7c478bd9Sstevel@tonic-gate fprintf(stderr, 583*7c478bd9Sstevel@tonic-gate gettext("\nInternal error." 584*7c478bd9Sstevel@tonic-gate " Conversion to hex failed.")); 585*7c478bd9Sstevel@tonic-gate status = 0; 586*7c478bd9Sstevel@tonic-gate goto cleanup; 587*7c478bd9Sstevel@tonic-gate } 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate } /* mechOidStr != NULL */ 590*7c478bd9Sstevel@tonic-gate 591*7c478bd9Sstevel@tonic-gate /* are we deleting the entire table or an entire mech ? */ 592*7c478bd9Sstevel@tonic-gate if (name == NULL && uidStr == NULL) { 593*7c478bd9Sstevel@tonic-gate 594*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 595*7c478bd9Sstevel@tonic-gate status = file_removeUsers(userMechOid, 596*7c478bd9Sstevel@tonic-gate NULL, &errDetails); 597*7c478bd9Sstevel@tonic-gate else 598*7c478bd9Sstevel@tonic-gate status = 0; 599*7c478bd9Sstevel@tonic-gate 600*7c478bd9Sstevel@tonic-gate /* display any errors */ 601*7c478bd9Sstevel@tonic-gate if (errDetails) { 602*7c478bd9Sstevel@tonic-gate fprintf(stderr, 603*7c478bd9Sstevel@tonic-gate gettext("\nError deleting gsscred entry " 604*7c478bd9Sstevel@tonic-gate "[%s]."), 605*7c478bd9Sstevel@tonic-gate errDetails); 606*7c478bd9Sstevel@tonic-gate free(errDetails); 607*7c478bd9Sstevel@tonic-gate errDetails = NULL; 608*7c478bd9Sstevel@tonic-gate } 609*7c478bd9Sstevel@tonic-gate goto cleanup; 610*7c478bd9Sstevel@tonic-gate } 611*7c478bd9Sstevel@tonic-gate 612*7c478bd9Sstevel@tonic-gate /* are we deleting by uid or uid and mech? */ 613*7c478bd9Sstevel@tonic-gate if (name == NULL && uidStr != NULL) { 614*7c478bd9Sstevel@tonic-gate 615*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 616*7c478bd9Sstevel@tonic-gate status = file_removeUsers(userMechOid, uidStr, 617*7c478bd9Sstevel@tonic-gate &errDetails); 618*7c478bd9Sstevel@tonic-gate else 619*7c478bd9Sstevel@tonic-gate status = 0; 620*7c478bd9Sstevel@tonic-gate 621*7c478bd9Sstevel@tonic-gate /* check for any errors */ 622*7c478bd9Sstevel@tonic-gate if (errDetails) { 623*7c478bd9Sstevel@tonic-gate fprintf(stderr, 624*7c478bd9Sstevel@tonic-gate gettext("\nError deleting gsscred entry " 625*7c478bd9Sstevel@tonic-gate "[%s]."), 626*7c478bd9Sstevel@tonic-gate errDetails); 627*7c478bd9Sstevel@tonic-gate free(errDetails); 628*7c478bd9Sstevel@tonic-gate errDetails = NULL; 629*7c478bd9Sstevel@tonic-gate } 630*7c478bd9Sstevel@tonic-gate goto cleanup; 631*7c478bd9Sstevel@tonic-gate } 632*7c478bd9Sstevel@tonic-gate 633*7c478bd9Sstevel@tonic-gate /* 634*7c478bd9Sstevel@tonic-gate * We are deleting by name; 635*7c478bd9Sstevel@tonic-gate * how many mechs must we check? 636*7c478bd9Sstevel@tonic-gate */ 637*7c478bd9Sstevel@tonic-gate if (mechOidStr == NULL) { 638*7c478bd9Sstevel@tonic-gate 639*7c478bd9Sstevel@tonic-gate if (gss_indicate_mechs(&minor, &mechSet) != GSS_S_COMPLETE) { 640*7c478bd9Sstevel@tonic-gate fprintf(stderr, 641*7c478bd9Sstevel@tonic-gate gettext("\nInternal error. " 642*7c478bd9Sstevel@tonic-gate "GSS-API call failed.")); 643*7c478bd9Sstevel@tonic-gate status = 0; 644*7c478bd9Sstevel@tonic-gate goto cleanup; 645*7c478bd9Sstevel@tonic-gate } 646*7c478bd9Sstevel@tonic-gate numOfMechs = mechSet->count; 647*7c478bd9Sstevel@tonic-gate } 648*7c478bd9Sstevel@tonic-gate else 649*7c478bd9Sstevel@tonic-gate numOfMechs = 1; 650*7c478bd9Sstevel@tonic-gate 651*7c478bd9Sstevel@tonic-gate /* now look through all the mechs, deleting */ 652*7c478bd9Sstevel@tonic-gate for (i = 0; i < numOfMechs; i++) { 653*7c478bd9Sstevel@tonic-gate 654*7c478bd9Sstevel@tonic-gate if (mechOidStr == NULL) { 655*7c478bd9Sstevel@tonic-gate anOid = &mechSet->elements[i]; 656*7c478bd9Sstevel@tonic-gate inBufDesc.length = anOid->length; 657*7c478bd9Sstevel@tonic-gate inBufDesc.value = anOid->elements; 658*7c478bd9Sstevel@tonic-gate outBufDesc.length = sizeof (hexMech); 659*7c478bd9Sstevel@tonic-gate outBufDesc.value = hexMech; 660*7c478bd9Sstevel@tonic-gate if (!gsscred_AsHex(&inBufDesc, &outBufDesc)) 661*7c478bd9Sstevel@tonic-gate continue; 662*7c478bd9Sstevel@tonic-gate } else 663*7c478bd9Sstevel@tonic-gate anOid = userMechOid; 664*7c478bd9Sstevel@tonic-gate 665*7c478bd9Sstevel@tonic-gate /* create a gss name */ 666*7c478bd9Sstevel@tonic-gate if (!gsscred_MakeName(anOid, name, nameOidStr, &outBufDesc)) 667*7c478bd9Sstevel@tonic-gate continue; 668*7c478bd9Sstevel@tonic-gate 669*7c478bd9Sstevel@tonic-gate /* now convert it to hex, and delete it */ 670*7c478bd9Sstevel@tonic-gate searchName.value = hexName; 671*7c478bd9Sstevel@tonic-gate searchName.length = sizeof (hexName); 672*7c478bd9Sstevel@tonic-gate status = gsscred_AsHex(&outBufDesc, &searchName); 673*7c478bd9Sstevel@tonic-gate free(outBufDesc.value); 674*7c478bd9Sstevel@tonic-gate 675*7c478bd9Sstevel@tonic-gate if (!status) 676*7c478bd9Sstevel@tonic-gate continue; 677*7c478bd9Sstevel@tonic-gate 678*7c478bd9Sstevel@tonic-gate if (tableSource == GSSCRED_FLAT_FILE) 679*7c478bd9Sstevel@tonic-gate status = file_deleteGssCredEntry(&searchName, 680*7c478bd9Sstevel@tonic-gate uidStr, &errDetails); 681*7c478bd9Sstevel@tonic-gate else 682*7c478bd9Sstevel@tonic-gate status = 0; 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate /* check for any errors */ 685*7c478bd9Sstevel@tonic-gate if (errDetails) { 686*7c478bd9Sstevel@tonic-gate fprintf(stderr, 687*7c478bd9Sstevel@tonic-gate gettext("\nError deleting gsscred entry" 688*7c478bd9Sstevel@tonic-gate " [%s]."), 689*7c478bd9Sstevel@tonic-gate errDetails); 690*7c478bd9Sstevel@tonic-gate free(errDetails); 691*7c478bd9Sstevel@tonic-gate errDetails = NULL; 692*7c478bd9Sstevel@tonic-gate } 693*7c478bd9Sstevel@tonic-gate } /* for */ 694*7c478bd9Sstevel@tonic-gate 695*7c478bd9Sstevel@tonic-gate cleanup: 696*7c478bd9Sstevel@tonic-gate if (mechSet != NULL) 697*7c478bd9Sstevel@tonic-gate gss_release_oid_set(&minor, &mechSet); 698*7c478bd9Sstevel@tonic-gate 699*7c478bd9Sstevel@tonic-gate return (status); 700*7c478bd9Sstevel@tonic-gate } /* removeUsers */ 701*7c478bd9Sstevel@tonic-gate 702*7c478bd9Sstevel@tonic-gate 703*7c478bd9Sstevel@tonic-gate /* 704*7c478bd9Sstevel@tonic-gate * Performs additional handling while deleting users 705*7c478bd9Sstevel@tonic-gate * stored in the flat file table. 706*7c478bd9Sstevel@tonic-gate */ 707*7c478bd9Sstevel@tonic-gate int file_removeUsers(const gss_OID mechOid, const char *unixUid, 708*7c478bd9Sstevel@tonic-gate char **errDetails) 709*7c478bd9Sstevel@tonic-gate { 710*7c478bd9Sstevel@tonic-gate gss_buffer_desc mechBufDesc = GSS_C_EMPTY_BUFFER, 711*7c478bd9Sstevel@tonic-gate mechHexBufDesc = GSS_C_EMPTY_BUFFER; 712*7c478bd9Sstevel@tonic-gate char mechBuf[128], mechHexBuf[256]; 713*7c478bd9Sstevel@tonic-gate 714*7c478bd9Sstevel@tonic-gate if (mechOid != NULL) { 715*7c478bd9Sstevel@tonic-gate /* 716*7c478bd9Sstevel@tonic-gate * need to create the buffer header which contains 717*7c478bd9Sstevel@tonic-gate * the mechanism oid. 718*7c478bd9Sstevel@tonic-gate */ 719*7c478bd9Sstevel@tonic-gate mechBufDesc.value = (void*) mechBuf; 720*7c478bd9Sstevel@tonic-gate mechBufDesc.length = sizeof (mechBuf); 721*7c478bd9Sstevel@tonic-gate mechHexBufDesc.value = (void *) mechHexBuf; 722*7c478bd9Sstevel@tonic-gate mechHexBufDesc.length = sizeof (mechHexBuf); 723*7c478bd9Sstevel@tonic-gate 724*7c478bd9Sstevel@tonic-gate if ((!gsscred_MakeNameHeader(mechOid, &mechBufDesc)) || 725*7c478bd9Sstevel@tonic-gate (!gsscred_AsHex(&mechBufDesc, &mechHexBufDesc))) { 726*7c478bd9Sstevel@tonic-gate (*errDetails) = strdup( 727*7c478bd9Sstevel@tonic-gate gettext("\nInternal error." 728*7c478bd9Sstevel@tonic-gate " Conversion to hex failed.")); 729*7c478bd9Sstevel@tonic-gate return (0); 730*7c478bd9Sstevel@tonic-gate } 731*7c478bd9Sstevel@tonic-gate 732*7c478bd9Sstevel@tonic-gate return (file_deleteGssCredEntry(&mechHexBufDesc, unixUid, 733*7c478bd9Sstevel@tonic-gate errDetails)); 734*7c478bd9Sstevel@tonic-gate } 735*7c478bd9Sstevel@tonic-gate 736*7c478bd9Sstevel@tonic-gate return (file_deleteGssCredEntry(NULL, unixUid, errDetails)); 737*7c478bd9Sstevel@tonic-gate } /* file_removeUsers */ 738*7c478bd9Sstevel@tonic-gate 739*7c478bd9Sstevel@tonic-gate 740*7c478bd9Sstevel@tonic-gate /* 741*7c478bd9Sstevel@tonic-gate * Prints the usage string, and terminates. 742*7c478bd9Sstevel@tonic-gate */ 743*7c478bd9Sstevel@tonic-gate static void usage(void) 744*7c478bd9Sstevel@tonic-gate { 745*7c478bd9Sstevel@tonic-gate 746*7c478bd9Sstevel@tonic-gate fprintf(stderr, 747*7c478bd9Sstevel@tonic-gate gettext("\nUsage:\t %s [-n user [-o oid] [-u uid]]" 748*7c478bd9Sstevel@tonic-gate " [-c comment] -m mech -a" 749*7c478bd9Sstevel@tonic-gate "\n\t %s [-n user [-o oid]] [-u uid] [-m mech] -r" 750*7c478bd9Sstevel@tonic-gate "\n\t %s [-n user [-o oid]] [-u uid] [-m mech] -l\n"), 751*7c478bd9Sstevel@tonic-gate PROG_NAME, PROG_NAME, PROG_NAME); 752*7c478bd9Sstevel@tonic-gate exit(1); 753*7c478bd9Sstevel@tonic-gate } /* usage */ 754