usr/src/cmd/iscsiadm/iscsiadm_main.c
changeset 12546 b9d61378e1b8
parent 12161 1b0453703429
equal deleted inserted replaced
12545:4850116ee928 12546:b9d61378e1b8
  3105 {
  3105 {
  3106 	IMA_INITIATOR_AUTHPARMS authParams;
  3106 	IMA_INITIATOR_AUTHPARMS authParams;
  3107 	IMA_STATUS status;
  3107 	IMA_STATUS status;
  3108 	int ret;
  3108 	int ret;
  3109 	int secretLen = MAX_CHAP_SECRET_LEN;
  3109 	int secretLen = MAX_CHAP_SECRET_LEN;
       
  3110 	int nameLen = 0;
  3110 
  3111 
  3111 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
  3112 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
  3112 
  3113 
  3113 	assert(funcRet != NULL);
  3114 	assert(funcRet != NULL);
  3114 
  3115 
  3124 	case AUTH_NAME:
  3125 	case AUTH_NAME:
  3125 		if (chapName == NULL) {
  3126 		if (chapName == NULL) {
  3126 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
  3127 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
  3127 			return (1);
  3128 			return (1);
  3128 		}
  3129 		}
  3129 		if (strlen(chapName) == 0) {
  3130 		nameLen = strlen(chapName);
       
  3131 		if (nameLen == 0) {
  3130 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
  3132 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
       
  3133 			return (1);
       
  3134 		}
       
  3135 		if (nameLen > ISCSI_MAX_C_USER_LEN) {
       
  3136 			(void) fprintf(stderr, "CHAP name is too long.\n");
  3131 			return (1);
  3137 			return (1);
  3132 		}
  3138 		}
  3133 		(void) memset(&authParams.chapParms.name, 0,
  3139 		(void) memset(&authParams.chapParms.name, 0,
  3134 		    sizeof (authParams.chapParms.name));
  3140 		    sizeof (authParams.chapParms.name));
  3135 		(void) memcpy(&authParams.chapParms.name,
  3141 		(void) memcpy(&authParams.chapParms.name,
  3136 		    &chapName[0], strlen(chapName));
  3142 		    &chapName[0], nameLen);
  3137 		authParams.chapParms.nameLength = strlen(chapName);
  3143 		authParams.chapParms.nameLength = nameLen;
  3138 		break;
  3144 		break;
  3139 
  3145 
  3140 	case AUTH_PASSWORD :
  3146 	case AUTH_PASSWORD :
  3141 		ret = getSecret((char *)&chapSecret[0], &secretLen,
  3147 		ret = getSecret((char *)&chapSecret[0], &secretLen,
  3142 		    MIN_CHAP_SECRET_LEN, MAX_CHAP_SECRET_LEN);
  3148 		    MIN_CHAP_SECRET_LEN, MAX_CHAP_SECRET_LEN);
  3174 {
  3180 {
  3175 	IMA_INITIATOR_AUTHPARMS authParams;
  3181 	IMA_INITIATOR_AUTHPARMS authParams;
  3176 	IMA_STATUS status;
  3182 	IMA_STATUS status;
  3177 	int ret;
  3183 	int ret;
  3178 	int secretLen = MAX_CHAP_SECRET_LEN;
  3184 	int secretLen = MAX_CHAP_SECRET_LEN;
       
  3185 	int nameLen = 0;
  3179 
  3186 
  3180 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
  3187 	IMA_BYTE chapSecret[MAX_CHAP_SECRET_LEN + 1];
  3181 
  3188 
  3182 	assert(funcRet != NULL);
  3189 	assert(funcRet != NULL);
  3183 
  3190 
  3193 	case AUTH_NAME:
  3200 	case AUTH_NAME:
  3194 		if (chapName == NULL) {
  3201 		if (chapName == NULL) {
  3195 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
  3202 			(void) fprintf(stderr, "CHAP name cannot be NULL.\n");
  3196 			return (1);
  3203 			return (1);
  3197 		}
  3204 		}
  3198 		if (strlen(chapName) == 0) {
  3205 		nameLen = strlen(chapName);
       
  3206 		if (nameLen == 0) {
  3199 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
  3207 			(void) fprintf(stderr, "CHAP name cannot be empty.\n");
       
  3208 			return (1);
       
  3209 		}
       
  3210 		if (nameLen > ISCSI_MAX_C_USER_LEN) {
       
  3211 			(void) fprintf(stderr, "CHAP name is too long.\n");
  3200 			return (1);
  3212 			return (1);
  3201 		}
  3213 		}
  3202 		(void) memset(&authParams.chapParms.name, 0,
  3214 		(void) memset(&authParams.chapParms.name, 0,
  3203 		    sizeof (authParams.chapParms.name));
  3215 		    sizeof (authParams.chapParms.name));
  3204 		(void) memcpy(&authParams.chapParms.name,
  3216 		(void) memcpy(&authParams.chapParms.name,
  3205 		    &chapName[0], strlen(chapName));
  3217 		    &chapName[0], nameLen);
  3206 		authParams.chapParms.nameLength = strlen(chapName);
  3218 		authParams.chapParms.nameLength = nameLen;
  3207 		break;
  3219 		break;
  3208 
  3220 
  3209 	case AUTH_PASSWORD :
  3221 	case AUTH_PASSWORD :
  3210 		ret = getSecret((char *)&chapSecret[0], &secretLen,
  3222 		ret = getSecret((char *)&chapSecret[0], &secretLen,
  3211 		    1, MAX_CHAP_SECRET_LEN);
  3223 		    1, MAX_CHAP_SECRET_LEN);