12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "mount.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <sys/mount.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <string.h>
- int next_word(FILE* f, char* out)
- {
- int i,c;
- for(i=0; (c=fgetc(f))!='\t' && c!=' ' && c!='\n' && c!=EOF; i++)
- out[i]=c;
- out[i]=0;
-
- if(c=='\n') return 1;
- if(c==' ' || c=='\t') return 0;
- if(c==EOF) return -1;
- }
- int is_mounted(const char* mp)
- {
- int c=0;
- char buf[2048];
- FILE* f = fopen("/proc/mounts", "r");
- if(!f)
- {
- fprintf(stderr, "Errue unable to open '/proc/mounts' ");
- perror(" ");
- return -1;
- }
-
- while(c>=0)
- {
- next_word(f, buf);
- next_word(f, buf);
- if(!strcmp(buf, mp))
- {
- fclose(f);
- return 1;
- }
- while((c=next_word(f, buf))==0);
- }
-
-
-
- fclose(f);
- return 0;
- }
- int mount_samba(config_t* cfg)
- {
- int tomount=config_get_int(cfg, "mount");
- char buffer[4096];
- const char* ip = config_get_string(cfg, "mount.ip");
- const char* src = config_get_string(cfg, "mount.src");
- const char* dst = config_get_string(cfg, "mount.dst");
- const char* username = config_get_string(cfg, "mount.username");
- const char* password = config_get_string(cfg, "mount.password");
-
- if(!tomount) return 0;
-
- sprintf(buffer, "unc=%s,ip=%s,username=%s,password=%s", src, ip, username, password);
- printf("%s\n", buffer);
-
- if(mount(src, dst, "cifs", MS_MGC_VAL | MS_SILENT, buffer))
- {
- fprintf(stderr, "Erreur unable to mount : %s\n", strerror(errno));
- return errno;
- }
- return 0;
- }
|