예제 #1
0
파일: Group.c 프로젝트: bagdxk/openafs
/**
 * Adds a user to the specified group. 
 *
 * env      the Java environment
 * cls      the current Java class
 * cellHandle    the handle of the cell to which the group belongs
 * jgroupName          the name of the group to which to add a member
 * juserName      the name of the user to add
 */
JNIEXPORT void JNICALL 
Java_org_openafs_jafs_Group_addMember
  (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupName,
   jstring juserName )
{
  afs_status_t ast;
  const char *groupName;
  const char *userName;

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

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

  if( !pts_GroupMemberAdd( (void *) cellHandle, userName, groupName, &ast ) ) {
    if( groupName != NULL ) {
      (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
    }
    if( userName != NULL ) {
      (*env)->ReleaseStringUTFChars(env, juserName, userName);
    }
    throwAFSException( env, ast );
    return;
  }

  if( groupName != NULL ) {
    (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
  }
  if( userName != NULL ) {
    (*env)->ReleaseStringUTFChars(env, juserName, userName);
  }
}
예제 #2
0
파일: pts.c 프로젝트: adeason/openafs
int
DoPtsGroupMemberAdd(struct cmd_syndesc *as, void *arock)
{
    enum { USER, GROUP };
    afs_status_t st = 0;
    const char *user = as->parms[USER].items->data;
    const char *group = as->parms[GROUP].items->data;

    if (!pts_GroupMemberAdd(cellHandle, user, group, &st)) {
	ERR_ST_EXT("pts_GroupMemberAdd", st);
    }

    return 0;
}
예제 #3
0
/*
 * cfg_HostSetAdminPrincipal() -- Put generic administrator principal in
 *     host's UserList; principal is created if it does not exist.
 *
 *     If first server host in cell, passwd and afsUid must be the initial
 *     password and the AFS UID for the admin principal; the admin principal
 *     is created.
 *
 *     If additional server host, passwd and afsUid are ignored; the admin
 *     principal is assumed to exist.
 *
 * ASSUMPTIONS: Client configured and BOS server started; if first host in
 *     cell then Authentication and Protection servers must be started as well.
 */
int ADMINAPI
cfg_HostSetAdminPrincipal(void *hostHandle,	/* host config handle */
			  short isFirst,	/* first server in cell flag */
			  const char *admin,	/* admin principal name */
			  const char *passwd,	/* admin initial password */
			  unsigned int afsUid,	/* admin AFS UID */
			  afs_status_p st)
{				/* completion status */
    int rc = 1;
    afs_status_t tst2, tst = 0;
    cfg_host_p cfg_host = (cfg_host_p) hostHandle;

    /* validate parameters and prepare host handle for bos functions */

    if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
	tst = tst2;
    } else if (admin == NULL || *admin == '\0') {
	tst = ADMCFGADMINPRINCIPALNULL;
    } else if (strlen(admin) > (KAS_MAX_NAME_LEN - 1)) {
	tst = ADMCFGADMINPRINCIPALTOOLONG;
    } else if (isFirst && (passwd == NULL || *passwd == '\0')) {
	tst = ADMCFGPASSWDNULL;
    } else if (!cfgutil_HostHandleBosInit(cfg_host, &tst2)) {
	tst = tst2;
    }

    /* put admin in host's UserList */

    if (tst == 0) {
	if (isFirst) {
	    /* first server host in cell; create admin principal */
	    kas_identity_t adminIdentity;
	    int adminUid = afsUid;
	    kas_admin_t adminFlag = KAS_ADMIN;

	    strcpy(adminIdentity.principal, admin);
	    adminIdentity.instance[0] = '\0';

	    if (!kas_PrincipalCreate
		(cfg_host->cellHandle, NULL, &adminIdentity, passwd, &tst2)
		&& tst2 != KAEXIST) {
		/* failed to create principal (and not because existed) */
		tst = tst2;

	    } else
		if (!kas_PrincipalFieldsSet
		    (cfg_host->cellHandle, NULL, &adminIdentity, &adminFlag,
		     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
		     &tst2)) {
		/* failed to set admin attributes */
		tst = tst2;

	    } else
		if (!pts_UserCreate
		    (cfg_host->cellHandle, admin, &adminUid, &tst2)
		    && tst2 != PREXIST) {
		/* failed to create user (and not because existed) */
		tst = tst2;

	    } else
		if (!pts_GroupMemberAdd
		    (cfg_host->cellHandle, admin, "system:administrators",
		     &tst2) && tst2 != PRIDEXIST) {
		/* failed to add to group (not because already there) */
		tst = tst2;
	    }
	}

	if (tst == 0) {
	    /* add admin to host's UserList */
	    if (!bos_AdminCreate(cfg_host->bosHandle, admin, &tst2)
		&& tst2 != EEXIST) {
		/* failed to add admin (and not because existed) */
		/* DANGER: platform-specific errno values being returned */
		tst = tst2;
	    }
	}
    }

    if (tst != 0) {
	rc = 0;
    }
    if (st != NULL) {
	*st = tst;
    }
    return rc;
}