Пример #1
0
/**
 * Create a server key.
 *
 * env      the Java environment
 * cls      the current Java class
 * cellHandle   the handle of the cell to which the server belongs
 * serverHandle  the bos handle of the server to which the key will 
 *                      belong
 * versionNumber   the version number of the key to create (0 to 255)
 * jkeyString     the String version of the key that will
 *                      be encrypted
 */
JNIEXPORT void JNICALL 
Java_org_openafs_jafs_Key_create
  (JNIEnv *env, jclass cls, jlong cellHandle, jlong serverHandle, jint version, 
   jstring jkeyString)
{
    afs_status_t ast;
    const char *keyString;
    char *cellName;
    kas_encryptionKey_p key = 
      (kas_encryptionKey_p) malloc( sizeof(kas_encryptionKey_t) );
    
    if( !key ) {
      throwAFSException( env, JAFSADMNOMEM );
      return;    
    }

    if( jkeyString != NULL ) {
      keyString = (*env)->GetStringUTFChars(env, jkeyString, 0);
      if( !keyString ) {
	  throwAFSException( env, JAFSADMNOMEM );
	  return;    
      }
    } else {
      keyString = NULL;
    }

    if( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) {
	free( key );
	if( keyString != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, jkeyString, keyString);
	}
	throwAFSException( env, ast );
	return;
    }   

    if( !kas_StringToKey( cellName, keyString, key, &ast ) ) {
	free( key );
	if( keyString != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, jkeyString, keyString);
	}
	throwAFSException( env, ast );
	return;
    }

    if( !bos_KeyCreate( (void *) serverHandle, version, key, &ast ) ) {
	free( key );
	if( keyString != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, jkeyString, keyString);
	}
	throwAFSException( env, ast );
	return;
    }

    free( key );
    if( keyString != NULL ) {
      (*env)->ReleaseStringUTFChars(env, jkeyString, keyString);
    }
}
Пример #2
0
/**
 * Returns the name of the cell.
 *
 *  env      the Java environment
 *  cls      the current Java class
 *  cellHandle    the handle of the cell to which the user belongs
 *  returns the name of the cell
 */
JNIEXPORT jstring JNICALL 
Java_org_openafs_jafs_Cell_getCellName (JNIEnv *env, jclass cls, 
					   jlong cellHandle) {

  afs_status_t ast;
  char *cellName;
  jstring jcellName;

  if( !afsclient_CellNameGet( (void *) cellHandle, 
			      (const char **) &cellName, &ast ) ) {
    throwAFSException( env, ast );
    return;
  }
  
  jcellName = (*env)->NewStringUTF(env, cellName);

  return jcellName;

}
Пример #3
0
/**
 * Sets the password of the given user.  Sets the key version to 0.
 *
 * env      the Java environment
 * cls      the current Java class
 * cellHandle    the handle of the cell to which the user belongs
 * juserName     the name of the user for which to set the password
 * jnewPassword     the new password for the user
 */
JNIEXPORT void JNICALL 
Java_org_openafs_jafs_User_setPassword
  (JNIEnv *env, jclass cls, jlong cellHandle, jstring juserName,
   jstring jnewPassword)
{
  afs_status_t ast;
  char *cellName;
  const char *userName;
  const char *newPassword;
  kas_encryptionKey_p newKey = 
    (kas_encryptionKey_p) malloc( sizeof(kas_encryptionKey_t) );
  kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) );

  if( !who || !newKey ) {
    if( who ) {
      free( who );
    }
    if( newKey ) {
      free( newKey );
    }
    throwAFSException( env, JAFSADMNOMEM );
    return;    
  }

  if( juserName != NULL ) {
      userName = (*env)->GetStringUTFChars(env, juserName, 0);
      if( !userName ) {
	  throwAFSException( env, JAFSADMNOMEM );
	  return;    
      }
  } else {
      userName = NULL;
  }
  if( jnewPassword != NULL ) {
      newPassword = (*env)->GetStringUTFChars(env, jnewPassword, 0);
      if( !newPassword ) {
	  throwAFSException( env, JAFSADMNOMEM );
	  return;    
      }
  } else {
      newPassword = NULL;
  }

  // make sure the name is within the allowed bounds
  if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) {
    free(who);
    free( newKey );
    if( userName != NULL ) {
	(*env)->ReleaseStringUTFChars(env, juserName, userName);
    }
    if( newPassword != NULL ) {
	(*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword);
    }
    throwAFSException( env, ADMPTSUSERNAMETOOLONG );
    return;
  }

  if( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) {
      free(who);
      free( newKey );
      if( userName != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, juserName, userName);
      }
      if( newPassword != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword);
      }
      throwAFSException( env, ast );
      return;
  }
  
  if( !kas_StringToKey( cellName, newPassword, newKey, &ast ) ) {
      free(who);
      free( newKey );
      if( userName != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, juserName, userName);
      }
      if( newPassword != NULL ) {
	  (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword);
      }
      throwAFSException( env, ast );
      return;
  }

  if( userName != NULL ) {
      internal_makeKasIdentity( userName, who );
  }

  ast = 0;
  // For some reason kas_PrincipalKeySet doesn't set the return code correctly.
  //  It always returns 0.
  // So instead of checking the return code, we see if there's an error 
  // in the status variable.
  kas_PrincipalKeySet( (void *) cellHandle, NULL, who, 0, newKey, &ast );
  if( ast ) {
    free( who );
    free( newKey );
    if( userName != NULL ) {
	(*env)->ReleaseStringUTFChars(env, juserName, userName);
    }
    if( newPassword != NULL ) {
	(*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword);
    }
    throwAFSException( env, ast );
    return;
  }

  free( who );
  free( newKey );
  if( userName != NULL ) {
      (*env)->ReleaseStringUTFChars(env, juserName, userName);
  }
  if( newPassword != NULL ) {
      (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword);
  }

}
Пример #4
0
/*
 * cfg_HostOpen() -- Obtain host configuration handle.
 */
int ADMINAPI
cfg_HostOpen(void *cellHandle,	/* cell handle */
	     const char *hostName,	/* name of host to configure */
	     void **hostHandleP,	/* host config handle */
	     afs_status_p st)
{				/* completion status */
    int rc = 1;
    afs_status_t tst2, tst = 0;
    cfg_host_p cfg_host;
    char fullHostName[MAXHOSTCHARS];

    /* validate parameters and resolve host name to fully qualified name */

    if (!CellHandleIsValid(cellHandle, &tst2)) {
	tst = tst2;
    } else if (hostName == NULL || *hostName == '\0') {
	tst = ADMCFGHOSTNAMENULL;
    } else if (strlen(hostName) > (MAXHOSTCHARS - 1)) {
	tst = ADMCFGHOSTNAMETOOLONG;
    } else if (hostHandleP == NULL) {
	tst = ADMCFGHOSTHANDLEPNULL;
    } else if (!cfgutil_HostNameGetFull(hostName, fullHostName, &tst2)) {
	tst = tst2;
    }

    /* remote configuration not yet supported; hostName must be local host */

    if (tst == 0) {
	short isLocal;

	if (!cfgutil_HostNameIsLocal(hostName, &isLocal, &tst2)) {
	    tst = tst2;
	} else if (!isLocal) {
	    tst = ADMCFGNOTSUPPORTED;
	}
    }

    /* allocate a host configuration handle */

    if (tst == 0) {
	char *localHostName;

	if ((cfg_host = (cfg_host_p) malloc(sizeof(cfg_host_t))) == NULL) {
	    tst = ADMNOMEM;
	} else if ((localHostName = (char *)malloc(strlen(fullHostName) + 1))
		   == NULL) {
	    free(cfg_host);
	    tst = ADMNOMEM;
	} else {
	    /* initialize handle */
	    cfg_host->begin_magic = BEGIN_MAGIC;
	    cfg_host->is_valid = 1;
	    cfg_host->hostName = localHostName;
	    cfg_host->is_local = 1;	/* not yet supporting remote config */
	    cfg_host->cellHandle = cellHandle;
	    cfg_host->bosHandle = NULL;
	    cfg_host->end_magic = END_MAGIC;

	    strcpy(localHostName, fullHostName);

	    if (!afsclient_CellNameGet
		(cfg_host->cellHandle, &cfg_host->cellName, &tst2)) {
		tst = tst2;
	    } else if (pthread_mutex_init(&cfg_host->mutex, NULL)) {
		tst = ADMMUTEXINIT;
	    }

	    if (tst != 0) {
		/* cell name lookup or mutex initialization failed */
		free(localHostName);
		free(cfg_host);
	    }
	}
    }

    if (tst == 0) {
	/* success; return host config handle to user */
	*hostHandleP = cfg_host;
    } else {
	/* indicate failure */
	rc = 0;
    }
    if (st != NULL) {
	*st = tst;
    }
    return rc;
}