mount.cifs: don't prompt for password on krb5 mounts
[ira/wip.git] / source3 / client / mount.cifs.c
index 1b67a5e8e6dc4319009099269b1fafa9af03d5e4..dd878aa07b41448fef6eb032183363976d5c9388 100644 (file)
@@ -115,6 +115,9 @@ size_t strlcat(char *d, const char *s, size_t bufsize)
        size_t ret = len1 + len2;
 
        if (len1+len2 >= bufsize) {
+               if (bufsize < (len1+1)) {
+                       return ret;
+               }
                len2 = bufsize - (len1+1);
        }
        if (len2 > 0) {
@@ -213,6 +216,7 @@ static int open_cred_file(char * file_name)
                                for(length = 0;length<4087;length++) {
                                        if ((temp_val[length] == '\n')
                                            || (temp_val[length] == '\0')) {
+                                               temp_val[length] = '\0';
                                                break;
                                        }
                                }
@@ -236,6 +240,7 @@ static int open_cred_file(char * file_name)
                                for(length = 0;length<MOUNT_PASSWD_SIZE+1;length++) {
                                        if ((temp_val[length] == '\n')
                                            || (temp_val[length] == '\0')) {
+                                               temp_val[length] = '\0';
                                                break;
                                        }
                                }
@@ -264,6 +269,7 @@ static int open_cred_file(char * file_name)
                                 for(length = 0;length<DOMAIN_SIZE+1;length++) {
                                        if ((temp_val[length] == '\n')
                                            || (temp_val[length] == '\0')) {
+                                               temp_val[length] = '\0';
                                                break;
                                        }
                                 }
@@ -330,6 +336,7 @@ static int get_password_from_file(int file_descript, char * filename)
                        break;
                } else /* read valid character */ {
                        if((c == 0) || (c == '\n')) {
+                               mountpassword[i] = '\0';
                                break;
                        } else 
                                mountpassword[i] = c;
@@ -466,7 +473,8 @@ static int parse_options(char ** optionsp, int * filesys_flags)
                        }
                } else if (strncmp(data, "sec", 3) == 0) {
                        if (value) {
-                               if (!strcmp(value, "none"))
+                               if (!strncmp(value, "none", 4) ||
+                                   !strncmp(value, "krb5", 4))
                                        got_password = 1;
                        }
                } else if (strncmp(data, "ip", 2) == 0) {
@@ -510,13 +518,16 @@ static int parse_options(char ** optionsp, int * filesys_flags)
                                printf("CIFS: UNC name too long\n");
                                return 1;
                        }
-               } else if ((strncmp(data, "domain", 3) == 0)
-                          || (strncmp(data, "workgroup", 5) == 0)) {
+               } else if ((strncmp(data, "dom" /* domain */, 3) == 0)
+                          || (strncmp(data, "workg", 5) == 0)) {
+                       /* note this allows for synonyms of "domain"
+                          such as "DOM" and "dom" and "workgroup"
+                          and "WORKGRP" etc. */
                        if (!value || !*value) {
                                printf("CIFS: invalid domain name\n");
                                return 1;       /* needs_arg; */
                        }
-                       if (strnlen(value, 65) < 65) {
+                       if (strnlen(value, DOMAIN_SIZE+1) < DOMAIN_SIZE+1) {
                                got_domain = 1;
                        } else {
                                printf("domain name too long\n");
@@ -1194,9 +1205,9 @@ int main(int argc, char ** argv)
 
        if (getenv("PASSWD")) {
                if(mountpassword == NULL)
-                       mountpassword = (char *)calloc(65,1);
+                       mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
                if(mountpassword) {
-                       strlcpy(mountpassword,getenv("PASSWD"),MOUNT_PASSWD_SIZE);
+                       strlcpy(mountpassword,getenv("PASSWD"),MOUNT_PASSWD_SIZE+1);
                        got_password = 1;
                }
        } else if (getenv("PASSWD_FD")) {