+ while(fgets(line_buf,4096,fs)) {
+ /* parse line from credential file */
+
+ /* eat leading white space */
+ for(i=0;i<4086;i++) {
+ if((line_buf[i] != ' ') && (line_buf[i] != '\t'))
+ break;
+ /* if whitespace - skip past it */
+ }
+ if (strncasecmp("username",line_buf+i,8) == 0) {
+ temp_val = strchr(line_buf + i,'=');
+ if(temp_val) {
+ /* go past equals sign */
+ temp_val++;
+ for(length = 0;length<4087;length++) {
+ if(temp_val[length] == '\n')
+ break;
+ }
+ if(length > 4086) {
+ printf("mount.cifs failed due to malformed username in credentials file");
+ memset(line_buf,0,4096);
+ if(mountpassword) {
+ memset(mountpassword,0,64);
+ }
+ exit(1);
+ } else {
+ got_user = 1;
+ user_name = (char *)calloc(1 + length,1);
+ /* BB adding free of user_name string before exit,
+ not really necessary but would be cleaner */
+ strncpy(user_name,temp_val, length);
+ }
+ }
+ } else if (strncasecmp("password",line_buf+i,8) == 0) {
+ temp_val = strchr(line_buf+i,'=');
+ if(temp_val) {
+ /* go past equals sign */
+ temp_val++;
+ for(length = 0;length<65;length++) {
+ if(temp_val[length] == '\n')
+ break;
+ }
+ if(length > 64) {
+ printf("mount.cifs failed: password in credentials file too long\n");
+ memset(line_buf,0, 4096);
+ if(mountpassword) {
+ memset(mountpassword,0,64);
+ }
+ exit(1);
+ } else {
+ if(mountpassword == NULL) {
+ mountpassword = (char *)calloc(65,1);
+ } else
+ memset(mountpassword,0,64);
+ if(mountpassword) {
+ strncpy(mountpassword,temp_val,length);
+ got_password = 1;
+ }
+ }
+ }
+ } else if (strncasecmp("domain",line_buf+i,6) == 0) {
+ temp_val = strchr(line_buf+i,'=');
+ if(temp_val) {
+ /* go past equals sign */
+ temp_val++;
+ if(verboseflag)
+ printf("\nDomain %s\n",temp_val);
+ for(length = 0;length<65;length++) {
+ if(temp_val[length] == '\n')
+ break;
+ }
+ if(length > 64) {
+ printf("mount.cifs failed: domain in credentials file too long\n");
+ if(mountpassword) {
+ memset(mountpassword,0,64);
+ }
+ exit(1);
+ } else {
+ if(domain_name == NULL) {
+ domain_name = (char *)calloc(65,1);
+ } else
+ memset(domain_name,0,64);
+ if(domain_name) {
+ strncpy(domain_name,temp_val,length);
+ got_domain = 1;
+ }
+ }
+ }
+ }
+
+ }
+ fclose(fs);
+ if(line_buf) {
+ memset(line_buf,0,4096);
+ free(line_buf);
+ }
+ return 0;
+}
+
+static int get_password_from_file(int file_descript, char * filename)
+{
+ int rc = 0;
+ int i;
+ char c;
+
+ if(mountpassword == NULL)
+ mountpassword = (char *)calloc(65,1);
+ else
+ memset(mountpassword, 0, 64);
+
+ if (mountpassword == NULL) {
+ printf("malloc failed\n");
+ exit(1);
+ }
+
+ if(filename != NULL) {
+ file_descript = open(filename, O_RDONLY);
+ if(file_descript < 0) {
+ printf("mount.cifs failed. %s attempting to open password file %s\n",
+ strerror(errno),filename);
+ exit(1);
+ }
+ }
+ /* else file already open and fd provided */
+
+ for(i=0;i<64;i++) {
+ rc = read(file_descript,&c,1);
+ if(rc < 0) {
+ printf("mount.cifs failed. Error %s reading password file\n",strerror(errno));
+ memset(mountpassword,0,64);
+ if(filename != NULL)
+ close(file_descript);
+ exit(1);
+ } else if(rc == 0) {
+ if(mountpassword[0] == 0) {
+ if(verboseflag)
+ printf("\nWarning: null password used since cifs password file empty");
+ }
+ break;
+ } else /* read valid character */ {
+ if((c == 0) || (c == '\n')) {
+ break;
+ } else
+ mountpassword[i] = c;
+ }
+ }
+ if((i == 64) && (verboseflag)) {
+ printf("\nWarning: password longer than 64 characters specified in cifs password file");
+ }
+ got_password = 1;
+ if(filename != NULL) {
+ close(file_descript);
+ }
+
+ return rc;
+}
+
+static int parse_options(char ** optionsp, int * filesys_flags)
+{
+ const char * data;
+ char * percent_char = NULL;
+ char * value = NULL;
+ char * next_keyword = NULL;
+ char * out = NULL;
+ int out_len = 0;
+ int word_len;
+ int rc = 0;
+
+ if (!optionsp || !*optionsp)