s3/passdb: clang: Value stored to 'c' is never read
[bbaumbach/samba-autobuild/.git] / source3 / passdb / pdb_smbpasswd.c
index 71b21fbb28fae0d4c14b74b27f029e5cd5625803..bed3cea744ca75e2e440402dff2127808de9015f 100644 (file)
@@ -39,7 +39,7 @@
 
 struct smb_passwd
 {
-        uint32 smb_userid;        /* this is actually the unix uid_t */
+        uint32_t smb_userid;      /* this is actually the unix uid_t */
         const char *smb_name;     /* username string */
 
         const unsigned char *smb_passwd;    /* Null if no password */
@@ -63,7 +63,7 @@ struct smbpasswd_privates
        unsigned char smbpwd[16];
        unsigned char smbntpwd[16];
 
-       /* retrive-once info */
+       /* retrieve-once info */
        const char *smbpasswd_file;
 };
 
@@ -87,7 +87,7 @@ static void gotalarm_sig(int signum)
 
 static bool do_file_lock(int fd, int waitsecs, int type)
 {
-       SMB_STRUCT_FLOCK lock;
+       struct flock lock;
        int             ret;
        void (*oldsig_handler)(int);
 
@@ -102,7 +102,7 @@ static bool do_file_lock(int fd, int waitsecs, int type)
 
        alarm(waitsecs);
        /* Note we must *NOT* use sys_fcntl here ! JRA */
-       ret = fcntl(fd, SMB_F_SETLKW, &lock);
+       ret = fcntl(fd, F_SETLKW, &lock);
        alarm(0);
        CatchSignal(SIGALRM, oldsig_handler);
 
@@ -214,7 +214,7 @@ static FILE *startsmbfilepwent(const char *pfile, enum pwf_access_type type, int
                                int i, fd = -1;
 
                                for(i = 0; i < 5; i++) {
-                                       if((fd = sys_open(pfile, O_CREAT|O_TRUNC|O_EXCL|O_RDWR, 0600))!=-1) {
+                                       if((fd = open(pfile, O_CREAT|O_TRUNC|O_EXCL|O_RDWR, 0600))!=-1) {
                                                break;
                                        }
                                        usleep(200); /* Spin, spin... */
@@ -237,14 +237,14 @@ creating file %s\n", pfile));
        for(race_loop = 0; race_loop < 5; race_loop++) {
                DEBUG(10, ("startsmbfilepwent_internal: opening file %s\n", pfile));
 
-               if((fp = sys_fopen(pfile, open_mode)) == NULL) {
+               if((fp = fopen(pfile, open_mode)) == NULL) {
 
                        /*
                         * If smbpasswd file doesn't exist, then create new one. This helps to avoid
                         * confusing error msg when adding user account first time.
                         */
                        if (errno == ENOENT) {
-                               if ((fp = sys_fopen(pfile, "a+")) != NULL) {
+                               if ((fp = fopen(pfile, "a+")) != NULL) {
                                        DEBUG(0, ("startsmbfilepwent_internal: file %s did not \
 exist. File successfully created.\n", pfile));
                                } else {
@@ -367,7 +367,6 @@ static struct smb_passwd *getsmbfilepwent(struct smbpasswd_privates *smbpasswd_s
        unsigned char *smbpwd = smbpasswd_state->smbpwd;
        unsigned char *smbntpwd = smbpasswd_state->smbntpwd;
        char linebuf[256];
-       int c;
        unsigned char *p;
        long uidval;
        size_t linebuf_len;
@@ -402,8 +401,8 @@ static struct smb_passwd *getsmbfilepwent(struct smbpasswd_privates *smbpasswd_s
                }
 
                if (linebuf[linebuf_len - 1] != '\n') {
-                       c = '\0';
                        while (!ferror(fp) && !feof(fp)) {
+                               int c;
                                c = fgetc(fp);
                                if (c == '\n') {
                                        break;
@@ -642,7 +641,7 @@ static NTSTATUS add_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state,
        int fd;
        size_t new_entry_length;
        char *new_entry;
-       SMB_OFF_T offpos;
+       off_t offpos;
  
        /* Open the smbpassword file - for update. */
        fp = startsmbfilepwent(pfile, PWF_UPDATE, &smbpasswd_state->pw_file_lock_depth);
@@ -737,10 +736,10 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, con
        fstring user_name;
 
        char *status;
-       char linebuf[256];
+#define LINEBUF_SIZE 255
+       char linebuf[LINEBUF_SIZE + 1];
        char readbuf[1024];
-       int c;
-       fstring ascii_p16;
+       char ascii_p16[FSTRING_LEN + 20];
        fstring encode_bits;
        unsigned char *p = NULL;
        size_t linebuf_len = 0;
@@ -750,7 +749,7 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, con
        bool found_entry = False;
        bool got_pass_last_set_time = False;
 
-       SMB_OFF_T pwd_seekpos = 0;
+       off_t pwd_seekpos = 0;
 
        int i;
        int wr_len;
@@ -762,7 +761,7 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, con
        }
        DEBUG(10, ("mod_smbfilepwd_entry: opening file %s\n", pfile));
 
-       fp = sys_fopen(pfile, "r+");
+       fp = fopen(pfile, "r+");
 
        if (fp == NULL) {
                DEBUG(0, ("mod_smbfilepwd_entry: unable to open file %s\n", pfile));
@@ -792,7 +791,7 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, con
 
                linebuf[0] = '\0';
 
-               status = fgets(linebuf, sizeof(linebuf), fp);
+               status = fgets(linebuf, LINEBUF_SIZE, fp);
                if (status == NULL && ferror(fp)) {
                        pw_file_unlock(lockfd, &smbpasswd_state->pw_file_lock_depth);
                        fclose(fp);
@@ -805,8 +804,8 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, con
                 */
                linebuf_len = strlen(linebuf);
                if (linebuf[linebuf_len - 1] != '\n') {
-                       c = '\0';
                        while (!ferror(fp) && !feof(fp)) {
+                               int c;
                                c = fgetc(fp);
                                if (c == '\n') {
                                        break;
@@ -1018,10 +1017,10 @@ This is no longer supported.!\n", pwd->smb_name));
 
 #ifdef DEBUG_PASSWORD
        DEBUG(100,("mod_smbfilepwd_entry: "));
-       dump_data(100, (uint8 *)ascii_p16, wr_len);
+       dump_data(100, (uint8_t *)ascii_p16, wr_len);
 #endif
 
-       if(wr_len > sizeof(linebuf)) {
+       if(wr_len > LINEBUF_SIZE) {
                DEBUG(0, ("mod_smbfilepwd_entry: line to write (%d) is too long.\n", wr_len+1));
                pw_file_unlock(lockfd,&smbpasswd_state->pw_file_lock_depth);
                fclose(fp);
@@ -1205,9 +1204,9 @@ static bool build_smb_pass (struct smb_passwd *smb_pw, const struct samu *sampas
 
                /* If the user specified a RID, make sure its able to be both stored and retreived */
                if (rid == DOMAIN_RID_GUEST) {
-                       struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guestaccount());
+                       struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guest_account());
                        if (!passwd) {
-                               DEBUG(0, ("Could not find guest account via Get_Pwnam_alloc()! (%s)\n", lp_guestaccount()));
+                               DEBUG(0, ("Could not find guest account via Get_Pwnam_alloc()! (%s)\n", lp_guest_account()));
                                return False;
                        }
                        smb_pw->smb_userid=passwd->pw_uid;
@@ -1331,20 +1330,21 @@ static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct sam
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
        struct smb_passwd *smb_pw;
+       struct dom_sid_buf buf;
        FILE *fp = NULL;
        uint32_t rid;
 
        DEBUG(10, ("smbpasswd_getsampwrid: search by sid: %s\n",
-                  sid_string_dbg(sid)));
+                  dom_sid_str_buf(sid, &buf)));
 
        if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid))
                return NT_STATUS_UNSUCCESSFUL;
 
        /* More special case 'guest account' hacks... */
        if (rid == DOMAIN_RID_GUEST) {
-               const char *guest_account = lp_guestaccount();
+               const char *guest_account = lp_guest_account();
                if (!(guest_account && *guest_account)) {
-                       DEBUG(1, ("Guest account not specfied!\n"));
+                       DEBUG(1, ("Guest account not specified!\n"));
                        return nt_status;
                }
                return smbpasswd_getsampwnam(my_methods, sam_acct, guest_account);
@@ -1381,9 +1381,11 @@ static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct sam
 
        /* build_sam_account might change the SID on us, if the name was for the guest account */
        if (NT_STATUS_IS_OK(nt_status) && !dom_sid_equal(pdb_get_user_sid(sam_acct), sid)) {
+               struct dom_sid_buf buf1, buf2;
                DEBUG(1, ("looking for user with sid %s instead returned %s "
-                         "for account %s!?!\n", sid_string_dbg(sid),
-                         sid_string_dbg(pdb_get_user_sid(sam_acct)),
+                         "for account %s!?!\n",
+                         dom_sid_str_buf(sid, &buf1),
+                         dom_sid_str_buf(pdb_get_user_sid(sam_acct), &buf2),
                          pdb_get_username(sam_acct)));
                return NT_STATUS_NO_SUCH_USER;
        }
@@ -1448,7 +1450,7 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
 
-       if (!*(lp_renameuser_script()))
+       if (!*(lp_rename_user_script(talloc_tos())))
                goto done;
 
        if ( !(new_acct = samu_new( NULL )) ) {
@@ -1468,8 +1470,7 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
        interim_account = True;
 
        /* rename the posix user */
-       rename_script = talloc_strdup(ctx,
-                               lp_renameuser_script());
+       rename_script = lp_rename_user_script(ctx);
        if (!rename_script) {
                ret = NT_STATUS_NO_MEMORY;
                goto done;
@@ -1501,7 +1502,7 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
                        goto done;
                }
 
-               rename_ret = smbrun(rename_script, NULL);
+               rename_ret = smbrun(rename_script, NULL, NULL);
 
                DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret));
 
@@ -1720,7 +1721,7 @@ static NTSTATUS pdb_init_smbpasswd( struct pdb_methods **pdb_method, const char
        return NT_STATUS_OK;
 }
 
-NTSTATUS pdb_smbpasswd_init(void
+NTSTATUS pdb_smbpasswd_init(TALLOC_CTX *ctx
 {
        return smb_register_passdb(PASSDB_INTERFACE_VERSION, "smbpasswd", pdb_init_smbpasswd);
 }