The manpage for /bin/mount specifies that the return code should be a
positive integer (actually, it's a bitfield). Clean up the return
codes from mount.cifs to make them match the expected return values
from /bin/mount. This necessary for proper integration with autofs.
This is the third attempt at this patch. The changes here are minor,
just changing some return's from main() into exit() calls for
consistency's sake.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
#define MOUNT_PASSWD_SIZE 64
#define DOMAIN_SIZE 64
#define MOUNT_PASSWD_SIZE 64
#define DOMAIN_SIZE 64
+/* exit status - bits below are ORed */
+#define EX_USAGE 1 /* incorrect invocation or permission */
+#define EX_SYSERR 2 /* out of memory, cannot fork, ... */
+#define EX_SOFTWARE 4 /* internal mount bug or wrong version */
+#define EX_USER 8 /* user interrupt */
+#define EX_FILEIO 16 /* problems writing, locking, ... mtab/fstab */
+#define EX_FAIL 32 /* mount failure */
+#define EX_SOMEOK 64 /* some mount succeeded */
+
const char *thisprogram;
int verboseflag = 0;
static int got_password = 0;
const char *thisprogram;
int verboseflag = 0;
static int got_password = 0;
printf("\n\t%s -V\n",thisprogram);
SAFE_FREE(mountpassword);
printf("\n\t%s -V\n",thisprogram);
SAFE_FREE(mountpassword);
}
/* caller frees username if necessary */
}
/* caller frees username if necessary */
if(length > 4086) {
printf("mount.cifs failed due to malformed username in credentials file");
memset(line_buf,0,4096);
if(length > 4086) {
printf("mount.cifs failed due to malformed username in credentials file");
memset(line_buf,0,4096);
} else {
got_user = 1;
user_name = (char *)calloc(1 + length,1);
} else {
got_user = 1;
user_name = (char *)calloc(1 + length,1);
if(length > MOUNT_PASSWD_SIZE) {
printf("mount.cifs failed: password in credentials file too long\n");
memset(line_buf,0, 4096);
if(length > MOUNT_PASSWD_SIZE) {
printf("mount.cifs failed: password in credentials file too long\n");
memset(line_buf,0, 4096);
} else {
if(mountpassword == NULL) {
mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
} else {
if(mountpassword == NULL) {
mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
}
if(length > DOMAIN_SIZE) {
printf("mount.cifs failed: domain in credentials file too long\n");
}
if(length > DOMAIN_SIZE) {
printf("mount.cifs failed: domain in credentials file too long\n");
} else {
if(domain_name == NULL) {
domain_name = (char *)calloc(DOMAIN_SIZE+1,1);
} else {
if(domain_name == NULL) {
domain_name = (char *)calloc(DOMAIN_SIZE+1,1);
if (mountpassword == NULL) {
printf("malloc failed\n");
if (mountpassword == NULL) {
printf("malloc failed\n");
if(file_descript < 0) {
printf("mount.cifs failed. %s attempting to open password file %s\n",
strerror(errno),filename);
if(file_descript < 0) {
printf("mount.cifs failed. %s attempting to open password file %s\n",
strerror(errno),filename);
}
}
/* else file already open and fd provided */
}
}
/* else file already open and fd provided */
printf("mount.cifs failed. Error %s reading password file\n",strerror(errno));
if(filename != NULL)
close(file_descript);
printf("mount.cifs failed. Error %s reading password file\n",strerror(errno));
if(filename != NULL)
close(file_descript);
} else if(rc == 0) {
if(mountpassword[0] == 0) {
if(verboseflag)
} else if(rc == 0) {
if(mountpassword[0] == 0) {
if(verboseflag)
if (!(pw = getpwnam(value))) {
printf("bad user name \"%s\"\n", value);
if (!(pw = getpwnam(value))) {
printf("bad user name \"%s\"\n", value);
}
snprintf(user, sizeof(user), "%u", pw->pw_uid);
} else {
}
snprintf(user, sizeof(user), "%u", pw->pw_uid);
} else {
if (!(gr = getgrnam(value))) {
printf("bad group name \"%s\"\n", value);
if (!(gr = getgrnam(value))) {
printf("bad group name \"%s\"\n", value);
}
snprintf(group, sizeof(group), "%u", gr->gr_gid);
} else {
}
snprintf(group, sizeof(group), "%u", gr->gr_gid);
} else {
out = (char *)realloc(out, out_len + word_len + 2);
if (out == NULL) {
perror("malloc");
out = (char *)realloc(out, out_len + word_len + 2);
if (out == NULL) {
perror("malloc");
out = (char *)realloc(out, out_len + word_len + 6);
if (out == NULL) {
perror("malloc");
out = (char *)realloc(out, out_len + word_len + 6);
if (out == NULL) {
perror("malloc");
out = (char *)realloc(out, out_len + 1 + word_len + 6);
if (out == NULL) {
perror("malloc");
out = (char *)realloc(out, out_len + 1 + word_len + 6);
if (out == NULL) {
perror("malloc");
thisprogram = argv[0];
} else {
mount_cifs_usage();
thisprogram = argv[0];
} else {
mount_cifs_usage();
}
if(thisprogram == NULL)
}
if(thisprogram == NULL)
share_name = strndup(argv[1], MAX_UNC_LEN);
if (share_name == NULL) {
fprintf(stderr, "%s: %s", argv[0], strerror(ENOMEM));
share_name = strndup(argv[1], MAX_UNC_LEN);
if (share_name == NULL) {
fprintf(stderr, "%s: %s", argv[0], strerror(ENOMEM));
}
mountpoint = argv[2];
} else {
mount_cifs_usage();
}
mountpoint = argv[2];
} else {
mount_cifs_usage();
}
/* add sharename in opts string as unc= parm */
}
/* add sharename in opts string as unc= parm */
case '?':
case 'h': /* help */
mount_cifs_usage ();
case '?':
case 'h': /* help */
mount_cifs_usage ();
case 'n':
++nomtab;
break;
case 'n':
++nomtab;
break;
uid = strtoul(optarg, &ep, 10);
if (*ep) {
printf("bad uid value \"%s\"\n", optarg);
uid = strtoul(optarg, &ep, 10);
if (*ep) {
printf("bad uid value \"%s\"\n", optarg);
}
} else {
struct passwd *pw;
if (!(pw = getpwnam(optarg))) {
printf("bad user name \"%s\"\n", optarg);
}
} else {
struct passwd *pw;
if (!(pw = getpwnam(optarg))) {
printf("bad user name \"%s\"\n", optarg);
}
uid = pw->pw_uid;
endpwent();
}
uid = pw->pw_uid;
endpwent();
gid = strtoul(optarg, &ep, 10);
if (*ep) {
printf("bad gid value \"%s\"\n", optarg);
gid = strtoul(optarg, &ep, 10);
if (*ep) {
printf("bad gid value \"%s\"\n", optarg);
}
} else {
struct group *gr;
if (!(gr = getgrnam(optarg))) {
printf("bad user name \"%s\"\n", optarg);
}
} else {
struct group *gr;
if (!(gr = getgrnam(optarg))) {
printf("bad user name \"%s\"\n", optarg);
}
gid = gr->gr_gid;
endpwent();
}
gid = gr->gr_gid;
endpwent();
default:
printf("unknown mount option %c\n",c);
mount_cifs_usage();
default:
printf("unknown mount option %c\n",c);
mount_cifs_usage();
}
}
if((argc < 3) || (dev_name == NULL) || (mountpoint == NULL)) {
mount_cifs_usage();
}
}
if((argc < 3) || (dev_name == NULL) || (mountpoint == NULL)) {
mount_cifs_usage();
}
if (getenv("PASSWD")) {
}
if (getenv("PASSWD")) {
}
if (orgoptions && parse_options(&orgoptions, &flags)) {
}
if (orgoptions && parse_options(&orgoptions, &flags)) {
goto mount_exit;
}
ipaddr = parse_server(&share_name);
if((ipaddr == NULL) && (got_ip == 0)) {
printf("No ip address specified and hostname not found\n");
goto mount_exit;
}
ipaddr = parse_server(&share_name);
if((ipaddr == NULL) && (got_ip == 0)) {
printf("No ip address specified and hostname not found\n");
}
if(chdir(mountpoint)) {
printf("mount error: can not change directory into mount target %s\n",mountpoint);
}
if(chdir(mountpoint)) {
printf("mount error: can not change directory into mount target %s\n",mountpoint);
goto mount_exit;
}
if(stat (".", &statbuf)) {
printf("mount error: mount point %s does not exist\n",mountpoint);
goto mount_exit;
}
if(stat (".", &statbuf)) {
printf("mount error: mount point %s does not exist\n",mountpoint);
goto mount_exit;
}
if (S_ISDIR(statbuf.st_mode) == 0) {
printf("mount error: mount point %s is not a directory\n",mountpoint);
goto mount_exit;
}
if (S_ISDIR(statbuf.st_mode) == 0) {
printf("mount error: mount point %s is not a directory\n",mountpoint);
#endif
} else {
printf("mount error: permission denied or not superuser and mount.cifs not installed SUID\n");
#endif
} else {
printf("mount error: permission denied or not superuser and mount.cifs not installed SUID\n");
mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
if (!tmp_pass || !mountpassword) {
printf("Password not entered, exiting\n");
mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
if (!tmp_pass || !mountpassword) {
printf("Password not entered, exiting\n");
}
strlcpy(mountpassword, tmp_pass, MOUNT_PASSWD_SIZE+1);
got_password = 1;
}
strlcpy(mountpassword, tmp_pass, MOUNT_PASSWD_SIZE+1);
got_password = 1;
else {
printf("No server share name specified\n");
printf("\nMounting the DFS root for server not implemented yet\n");
else {
printf("No server share name specified\n");
printf("\nMounting the DFS root for server not implemented yet\n");
}
if(user_name)
optlen += strlen(user_name) + 6;
}
if(user_name)
optlen += strlen(user_name) + 6;
if(options == NULL) {
printf("Could not allocate memory for mount options\n");
if(options == NULL) {
printf("Could not allocate memory for mount options\n");
printf("mount error %d = %s\n",errno,strerror(errno));
}
printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n");
printf("mount error %d = %s\n",errno,strerror(errno));
}
printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n");
- rc = -1;
- goto mount_exit;
} else {
pmntfile = setmntent(MOUNTED, "a+");
if(pmntfile) {
} else {
pmntfile = setmntent(MOUNTED, "a+");
if(pmntfile) {
rc = addmntent(pmntfile,&mountent);
endmntent(pmntfile);
SAFE_FREE(mountent.mnt_opts);
rc = addmntent(pmntfile,&mountent);
endmntent(pmntfile);
SAFE_FREE(mountent.mnt_opts);
+ if (rc)
+ rc = EX_FILEIO;
- printf("could not update mount table\n");
+ printf("could not update mount table\n");
+ rc = EX_FILEIO;
mount_exit:
if(mountpassword) {
int len = strlen(mountpassword);
mount_exit:
if(mountpassword) {
int len = strlen(mountpassword);
SAFE_FREE(orgoptions);
SAFE_FREE(resolved_path);
SAFE_FREE(share_name);
SAFE_FREE(orgoptions);
SAFE_FREE(resolved_path);
SAFE_FREE(share_name);